• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Amber Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SRC_VKSCRIPT_COMMAND_PARSER_H_
16 #define SRC_VKSCRIPT_COMMAND_PARSER_H_
17 
18 #include <memory>
19 #include <string>
20 #include <utility>
21 #include <vector>
22 
23 #include "amber/result.h"
24 #include "src/command.h"
25 #include "src/pipeline.h"
26 #include "src/pipeline_data.h"
27 #include "src/script.h"
28 
29 namespace amber {
30 
31 class Tokenizer;
32 class Token;
33 
34 namespace vkscript {
35 
36 /// Parses the contents of the [test] section of a VkScript file into individual
37 /// commands.
38 class CommandParser {
39  public:
40   CommandParser(Script* script,
41                 Pipeline* pipeline,
42                 size_t current_line,
43                 const std::string& data);
44   ~CommandParser();
45 
46   Result Parse();
47 
AddCommand(std::unique_ptr<Command> command)48   void AddCommand(std::unique_ptr<Command> command) {
49     commands_.push_back(std::move(command));
50   }
51 
Commands()52   const std::vector<std::unique_ptr<Command>>& Commands() const {
53     return commands_;
54   }
55 
TakeCommands()56   std::vector<std::unique_ptr<Command>>&& TakeCommands() {
57     return std::move(commands_);
58   }
59 
PipelineDataForTesting()60   const PipelineData* PipelineDataForTesting() const { return &pipeline_data_; }
61 
ParseBooleanForTesting(const std::string & str,bool * result)62   Result ParseBooleanForTesting(const std::string& str, bool* result) {
63     return ParseBoolean(str, result);
64   }
65 
ParseBlendFactorNameForTesting(const std::string & name,BlendFactor * factor)66   Result ParseBlendFactorNameForTesting(const std::string& name,
67                                         BlendFactor* factor) {
68     return ParseBlendFactorName(name, factor);
69   }
ParseBlendOpNameForTesting(const std::string & name,BlendOp * op)70   Result ParseBlendOpNameForTesting(const std::string& name, BlendOp* op) {
71     return ParseBlendOpName(name, op);
72   }
ParseCompareOpNameForTesting(const std::string & name,CompareOp * op)73   Result ParseCompareOpNameForTesting(const std::string& name, CompareOp* op) {
74     return ParseCompareOpName(name, op);
75   }
ParseStencilOpNameForTesting(const std::string & name,StencilOp * op)76   Result ParseStencilOpNameForTesting(const std::string& name, StencilOp* op) {
77     return ParseStencilOpName(name, op);
78   }
ParseComparatorForTesting(const std::string & name,ProbeSSBOCommand::Comparator * op)79   Result ParseComparatorForTesting(const std::string& name,
80                                    ProbeSSBOCommand::Comparator* op) {
81     return ParseComparator(name, op);
82   }
TolerancesForTesting()83   const std::vector<Probe::Tolerance>& TolerancesForTesting() const {
84     return current_tolerances_;
85   }
86 
87  private:
88   std::string make_error(const std::string& err);
89   Result TokenToFloat(Token* token, float* val) const;
90   Result TokenToDouble(Token* token, double* val) const;
91   Result ParseBoolean(const std::string& str, bool* result);
92   Result ParseValues(const std::string& name,
93                      Format* fmt,
94                      std::vector<Value>* values);
95 
96   Result ProcessDrawRect();
97   Result ProcessDrawArrays();
98   Result ProcessCompute();
99   Result ProcessClear();
100   Result ProcessPatch();
101   Result ProcessSSBO();
102   Result ProcessUniform();
103   Result ProcessTolerance();
104   Result ProcessEntryPoint(const std::string& name);
105   Result ProcessProbe(bool relative);
106   Result ProcessProbeSSBO();
107   Result ProcessTopology();
108   Result ProcessPolygonMode();
109   Result ProcessLogicOp();
110   Result ProcessCullMode();
111   Result ProcessFrontFace();
112   Result ProcessFloatPipelineData(const std::string& name, float* value);
113   Result ProcessDepthBiasConstantFactor();
114   Result ProcessDepthBiasClamp();
115   Result ProcessDepthBiasSlopeFactor();
116   Result ProcessLineWidth();
117   Result ProcessMinDepthBounds();
118   Result ProcessMaxDepthBounds();
119   Result ProcessBooleanPipelineData(const std::string& name, bool* value);
120   Result ProcessPrimitiveRestartEnable();
121   Result ProcessDepthClampEnable();
122   Result ProcessRasterizerDiscardEnable();
123   Result ProcessDepthBiasEnable();
124   Result ProcessLogicOpEnable();
125   Result ProcessBlendEnable();
126   Result ProcessDepthTestEnable();
127   Result ProcessDepthWriteEnable();
128   Result ProcessDepthBoundsTestEnable();
129   Result ProcessStencilTestEnable();
130   Result ParseBlendFactor(const std::string& name, BlendFactor* factor);
131   Result ParseBlendFactorName(const std::string& name, BlendFactor* factor);
132   Result ProcessSrcAlphaBlendFactor();
133   Result ProcessDstAlphaBlendFactor();
134   Result ProcessSrcColorBlendFactor();
135   Result ProcessDstColorBlendFactor();
136   Result ParseBlendOp(const std::string& name, BlendOp* op);
137   Result ParseBlendOpName(const std::string& name, BlendOp* op);
138   Result ProcessColorBlendOp();
139   Result ProcessAlphaBlendOp();
140   Result ParseCompareOp(const std::string& name, CompareOp* op);
141   Result ParseCompareOpName(const std::string& name, CompareOp* op);
142   Result ProcessDepthCompareOp();
143   Result ProcessFrontCompareOp();
144   Result ProcessBackCompareOp();
145   Result ParseStencilOp(const std::string& name, StencilOp* op);
146   Result ParseStencilOpName(const std::string& name, StencilOp* op);
147   Result ProcessFrontFailOp();
148   Result ProcessFrontPassOp();
149   Result ProcessFrontDepthFailOp();
150   Result ProcessBackFailOp();
151   Result ProcessBackPassOp();
152   Result ProcessBackDepthFailOp();
153   Result ProcessFrontCompareMask();
154   Result ProcessFrontWriteMask();
155   Result ProcessBackCompareMask();
156   Result ProcessBackWriteMask();
157   Result ProcessFrontReference();
158   Result ProcessBackReference();
159   Result ProcessColorWriteMask();
160   Result ParseComparator(const std::string& name,
161                          ProbeSSBOCommand::Comparator* op);
162 
163   Script* script_;
164   Pipeline* pipeline_;
165   PipelineData pipeline_data_;
166   std::unique_ptr<Tokenizer> tokenizer_;
167   std::vector<std::unique_ptr<Command>> commands_;
168   std::vector<Probe::Tolerance> current_tolerances_;
169 };
170 
171 }  // namespace vkscript
172 }  // namespace amber
173 
174 #endif  // SRC_VKSCRIPT_COMMAND_PARSER_H_
175