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_COMMAND_H_
16 #define SRC_COMMAND_H_
17 
18 #include <cstdint>
19 #include <memory>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
24 #include "amber/shader_info.h"
25 #include "amber/value.h"
26 #include "src/buffer.h"
27 #include "src/command_data.h"
28 #include "src/debug.h"
29 #include "src/pipeline_data.h"
30 #include "src/sampler.h"
31 
32 namespace amber {
33 
34 class BufferCommand;
35 class ClearColorCommand;
36 class ClearCommand;
37 class ClearDepthCommand;
38 class ClearStencilCommand;
39 class CompareBufferCommand;
40 class ComputeCommand;
41 class CopyCommand;
42 class DrawArraysCommand;
43 class DrawRectCommand;
44 class DrawGridCommand;
45 class EntryPointCommand;
46 class PatchParameterVerticesCommand;
47 class Pipeline;
48 class ProbeCommand;
49 class ProbeSSBOCommand;
50 class RepeatCommand;
51 
52 /// Base class for all commands.
53 class Command {
54  public:
55   enum class Type : uint8_t {
56     kClear = 0,
57     kClearColor,
58     kClearDepth,
59     kClearStencil,
60     kCompute,
61     kCompareBuffer,
62     kCopy,
63     kDrawArrays,
64     kDrawRect,
65     kDrawGrid,
66     kEntryPoint,
67     kPatchParameterVertices,
68     kPipelineProperties,
69     kProbe,
70     kProbeSSBO,
71     kBuffer,
72     kRepeat,
73     kSampler
74   };
75 
76   virtual ~Command();
77 
GetType()78   Command::Type GetType() const { return command_type_; }
79 
IsDrawRect()80   bool IsDrawRect() const { return command_type_ == Type::kDrawRect; }
IsDrawGrid()81   bool IsDrawGrid() const { return command_type_ == Type::kDrawGrid; }
IsDrawArrays()82   bool IsDrawArrays() const { return command_type_ == Type::kDrawArrays; }
IsCompareBuffer()83   bool IsCompareBuffer() const { return command_type_ == Type::kCompareBuffer; }
IsCompute()84   bool IsCompute() const { return command_type_ == Type::kCompute; }
IsCopy()85   bool IsCopy() const { return command_type_ == Type::kCopy; }
IsProbe()86   bool IsProbe() const { return command_type_ == Type::kProbe; }
IsProbeSSBO()87   bool IsProbeSSBO() const { return command_type_ == Type::kProbeSSBO; }
IsBuffer()88   bool IsBuffer() const { return command_type_ == Type::kBuffer; }
IsClear()89   bool IsClear() const { return command_type_ == Type::kClear; }
IsClearColor()90   bool IsClearColor() const { return command_type_ == Type::kClearColor; }
IsClearDepth()91   bool IsClearDepth() const { return command_type_ == Type::kClearDepth; }
IsClearStencil()92   bool IsClearStencil() const { return command_type_ == Type::kClearStencil; }
IsPatchParameterVertices()93   bool IsPatchParameterVertices() const {
94     return command_type_ == Type::kPatchParameterVertices;
95   }
IsEntryPoint()96   bool IsEntryPoint() const { return command_type_ == Type::kEntryPoint; }
IsRepeat()97   bool IsRepeat() { return command_type_ == Type::kRepeat; }
98 
99   ClearCommand* AsClear();
100   ClearColorCommand* AsClearColor();
101   ClearDepthCommand* AsClearDepth();
102   ClearStencilCommand* AsClearStencil();
103   CompareBufferCommand* AsCompareBuffer();
104   ComputeCommand* AsCompute();
105   CopyCommand* AsCopy();
106   DrawArraysCommand* AsDrawArrays();
107   DrawRectCommand* AsDrawRect();
108   DrawGridCommand* AsDrawGrid();
109   EntryPointCommand* AsEntryPoint();
110   PatchParameterVerticesCommand* AsPatchParameterVertices();
111   ProbeCommand* AsProbe();
112   ProbeSSBOCommand* AsProbeSSBO();
113   BufferCommand* AsBuffer();
114   RepeatCommand* AsRepeat();
115 
116   virtual std::string ToString() const = 0;
117 
118   /// Sets the input file line number this command is declared on.
SetLine(size_t line)119   void SetLine(size_t line) { line_ = line; }
120   /// Returns the input file line this command was declared on.
GetLine()121   size_t GetLine() const { return line_; }
122 
123   /// Sets the debug script to run for this command.
SetDebugScript(std::unique_ptr<debug::Script> && debug)124   void SetDebugScript(std::unique_ptr<debug::Script>&& debug) {
125     debug_ = std::move(debug);
126   }
127 
128   /// Returns the optional debug script associated with this command.
GetDebugScript()129   debug::Script* GetDebugScript() { return debug_.get(); }
130 
131  protected:
132   explicit Command(Type type);
133 
134   Type command_type_;
135   size_t line_ = 1;
136   std::unique_ptr<debug::Script> debug_;
137 };
138 
139 /// Base class for commands which contain a pipeline.
140 class PipelineCommand : public Command {
141  public:
142   ~PipelineCommand() override;
143 
GetPipeline()144   Pipeline* GetPipeline() const { return pipeline_; }
145 
146  protected:
147   PipelineCommand(Type type, Pipeline* pipeline);
148 
149   Pipeline* pipeline_ = nullptr;
150 };
151 
152 /// Command to draw a rectangle on screen.
153 class DrawRectCommand : public PipelineCommand {
154  public:
155   DrawRectCommand(Pipeline* pipeline, PipelineData data);
156   ~DrawRectCommand() override;
157 
GetPipelineData()158   const PipelineData* GetPipelineData() const { return &data_; }
159 
EnableOrtho()160   void EnableOrtho() { is_ortho_ = true; }
IsOrtho()161   bool IsOrtho() const { return is_ortho_; }
162 
EnablePatch()163   void EnablePatch() { is_patch_ = true; }
IsPatch()164   bool IsPatch() const { return is_patch_; }
165 
SetX(float x)166   void SetX(float x) { x_ = x; }
GetX()167   float GetX() const { return x_; }
168 
SetY(float y)169   void SetY(float y) { y_ = y; }
GetY()170   float GetY() const { return y_; }
171 
SetWidth(float w)172   void SetWidth(float w) { width_ = w; }
GetWidth()173   float GetWidth() const { return width_; }
174 
SetHeight(float h)175   void SetHeight(float h) { height_ = h; }
GetHeight()176   float GetHeight() const { return height_; }
177 
ToString()178   std::string ToString() const override { return "DrawRectCommand"; }
179 
180  private:
181   PipelineData data_;
182   bool is_ortho_ = false;
183   bool is_patch_ = false;
184   float x_ = 0.0;
185   float y_ = 0.0;
186   float width_ = 0.0;
187   float height_ = 0.0;
188 };
189 
190 /// Command to draw a grid of recrangles on screen.
191 class DrawGridCommand : public PipelineCommand {
192  public:
193   DrawGridCommand(Pipeline* pipeline, PipelineData data);
194   ~DrawGridCommand() override;
195 
GetPipelineData()196   const PipelineData* GetPipelineData() const { return &data_; }
197 
SetX(float x)198   void SetX(float x) { x_ = x; }
GetX()199   float GetX() const { return x_; }
200 
SetY(float y)201   void SetY(float y) { y_ = y; }
GetY()202   float GetY() const { return y_; }
203 
SetWidth(float w)204   void SetWidth(float w) { width_ = w; }
GetWidth()205   float GetWidth() const { return width_; }
206 
SetHeight(float h)207   void SetHeight(float h) { height_ = h; }
GetHeight()208   float GetHeight() const { return height_; }
209 
SetColumns(uint32_t c)210   void SetColumns(uint32_t c) { columns_ = c; }
GetColumns()211   uint32_t GetColumns() const { return columns_; }
212 
SetRows(uint32_t r)213   void SetRows(uint32_t r) { rows_ = r; }
GetRows()214   uint32_t GetRows() const { return rows_; }
215 
ToString()216   std::string ToString() const override { return "DrawGridCommand"; }
217 
218  private:
219   PipelineData data_;
220   float x_ = 0.0;
221   float y_ = 0.0;
222   float width_ = 0.0;
223   float height_ = 0.0;
224   uint32_t columns_ = 0;
225   uint32_t rows_ = 0;
226 };
227 
228 /// Command to draw from a vertex and index buffer.
229 class DrawArraysCommand : public PipelineCommand {
230  public:
231   DrawArraysCommand(Pipeline* pipeline, PipelineData data);
232   ~DrawArraysCommand() override;
233 
GetPipelineData()234   const PipelineData* GetPipelineData() const { return &data_; }
235 
EnableIndexed()236   void EnableIndexed() { is_indexed_ = true; }
IsIndexed()237   bool IsIndexed() const { return is_indexed_; }
238 
SetTopology(Topology topo)239   void SetTopology(Topology topo) { topology_ = topo; }
GetTopology()240   Topology GetTopology() const { return topology_; }
241 
SetFirstVertexIndex(uint32_t idx)242   void SetFirstVertexIndex(uint32_t idx) { first_vertex_index_ = idx; }
GetFirstVertexIndex()243   uint32_t GetFirstVertexIndex() const { return first_vertex_index_; }
244 
SetVertexCount(uint32_t count)245   void SetVertexCount(uint32_t count) { vertex_count_ = count; }
GetVertexCount()246   uint32_t GetVertexCount() const { return vertex_count_; }
247 
SetFirstInstance(uint32_t idx)248   void SetFirstInstance(uint32_t idx) { first_instance_ = idx; }
GetFirstInstance()249   uint32_t GetFirstInstance() const { return first_instance_; }
250 
SetInstanceCount(uint32_t count)251   void SetInstanceCount(uint32_t count) { instance_count_ = count; }
GetInstanceCount()252   uint32_t GetInstanceCount() const { return instance_count_; }
253 
ToString()254   std::string ToString() const override { return "DrawArraysCommand"; }
255 
256  private:
257   PipelineData data_;
258   bool is_indexed_ = false;
259   Topology topology_ = Topology::kUnknown;
260   uint32_t first_vertex_index_ = 0;
261   uint32_t vertex_count_ = 0;
262   uint32_t first_instance_ = 0;
263   uint32_t instance_count_ = 1;
264 };
265 
266 /// A command to compare two buffers.
267 class CompareBufferCommand : public Command {
268  public:
269   enum class Comparator { kEq, kRmse, kHistogramEmd };
270 
271   CompareBufferCommand(Buffer* buffer_1, Buffer* buffer_2);
272   ~CompareBufferCommand() override;
273 
GetBuffer1()274   Buffer* GetBuffer1() const { return buffer_1_; }
GetBuffer2()275   Buffer* GetBuffer2() const { return buffer_2_; }
276 
SetComparator(Comparator type)277   void SetComparator(Comparator type) { comparator_ = type; }
GetComparator()278   Comparator GetComparator() const { return comparator_; }
279 
SetTolerance(float tolerance)280   void SetTolerance(float tolerance) { tolerance_ = tolerance; }
GetTolerance()281   float GetTolerance() const { return tolerance_; }
282 
ToString()283   std::string ToString() const override { return "CompareBufferCommand"; }
284 
285  private:
286   Buffer* buffer_1_;
287   Buffer* buffer_2_;
288   float tolerance_ = 0.0;
289   Comparator comparator_ = Comparator::kEq;
290 };
291 
292 /// Command to execute a compute command.
293 class ComputeCommand : public PipelineCommand {
294  public:
295   explicit ComputeCommand(Pipeline* pipeline);
296   ~ComputeCommand() override;
297 
SetX(uint32_t x)298   void SetX(uint32_t x) { x_ = x; }
GetX()299   uint32_t GetX() const { return x_; }
300 
SetY(uint32_t y)301   void SetY(uint32_t y) { y_ = y; }
GetY()302   uint32_t GetY() const { return y_; }
303 
SetZ(uint32_t z)304   void SetZ(uint32_t z) { z_ = z; }
GetZ()305   uint32_t GetZ() const { return z_; }
306 
ToString()307   std::string ToString() const override { return "ComputeCommand"; }
308 
309  private:
310   uint32_t x_ = 0;
311   uint32_t y_ = 0;
312   uint32_t z_ = 0;
313 };
314 
315 /// Command to copy data from one buffer to another.
316 class CopyCommand : public Command {
317  public:
318   CopyCommand(Buffer* buffer_from, Buffer* buffer_to);
319   ~CopyCommand() override;
320 
GetBufferFrom()321   Buffer* GetBufferFrom() const { return buffer_from_; }
GetBufferTo()322   Buffer* GetBufferTo() const { return buffer_to_; }
323 
ToString()324   std::string ToString() const override { return "CopyCommand"; }
325 
326  private:
327   Buffer* buffer_from_;
328   Buffer* buffer_to_;
329 };
330 
331 /// Base class for probe commands.
332 class Probe : public Command {
333  public:
334   /// Wrapper around tolerance information for the probe.
335   struct Tolerance {
ToleranceTolerance336     Tolerance(bool percent, double val) : is_percent(percent), value(val) {}
337 
338     bool is_percent = false;
339     double value = 0.0;
340   };
341 
342   ~Probe() override;
343 
GetBuffer()344   Buffer* GetBuffer() const { return buffer_; }
345 
HasTolerances()346   bool HasTolerances() const { return !tolerances_.empty(); }
SetTolerances(const std::vector<Tolerance> & t)347   void SetTolerances(const std::vector<Tolerance>& t) { tolerances_ = t; }
GetTolerances()348   const std::vector<Tolerance>& GetTolerances() const { return tolerances_; }
349 
350  protected:
351   Probe(Type type, Buffer* buffer);
352 
353  private:
354   Buffer* buffer_;
355   std::vector<Tolerance> tolerances_;
356 };
357 
358 /// Command to probe an image buffer.
359 class ProbeCommand : public Probe {
360  public:
361   explicit ProbeCommand(Buffer* buffer);
362   ~ProbeCommand() override;
363 
SetWholeWindow()364   void SetWholeWindow() { is_whole_window_ = true; }
IsWholeWindow()365   bool IsWholeWindow() const { return is_whole_window_; }
366 
SetProbeRect()367   void SetProbeRect() { is_probe_rect_ = true; }
IsProbeRect()368   bool IsProbeRect() const { return is_probe_rect_; }
369 
SetRelative()370   void SetRelative() { is_relative_ = true; }
IsRelative()371   bool IsRelative() const { return is_relative_; }
372 
SetIsRGBA()373   void SetIsRGBA() { color_format_ = ColorFormat::kRGBA; }
IsRGBA()374   bool IsRGBA() const { return color_format_ == ColorFormat::kRGBA; }
375 
SetX(float x)376   void SetX(float x) { x_ = x; }
GetX()377   float GetX() const { return x_; }
378 
SetY(float y)379   void SetY(float y) { y_ = y; }
GetY()380   float GetY() const { return y_; }
381 
SetWidth(float w)382   void SetWidth(float w) { width_ = w; }
GetWidth()383   float GetWidth() const { return width_; }
384 
SetHeight(float h)385   void SetHeight(float h) { height_ = h; }
GetHeight()386   float GetHeight() const { return height_; }
387 
388   // Colours are stored in the range 0.0 - 1.0
SetR(float r)389   void SetR(float r) { r_ = r; }
GetR()390   float GetR() const { return r_; }
391 
SetG(float g)392   void SetG(float g) { g_ = g; }
GetG()393   float GetG() const { return g_; }
394 
SetB(float b)395   void SetB(float b) { b_ = b; }
GetB()396   float GetB() const { return b_; }
397 
SetA(float a)398   void SetA(float a) { a_ = a; }
GetA()399   float GetA() const { return a_; }
400 
ToString()401   std::string ToString() const override { return "ProbeCommand"; }
402 
403  private:
404   enum class ColorFormat {
405     kRGB = 0,
406     kRGBA,
407   };
408 
409   bool is_whole_window_ = false;
410   bool is_probe_rect_ = false;
411   bool is_relative_ = false;
412   ColorFormat color_format_ = ColorFormat::kRGB;
413 
414   float x_ = 0.0;
415   float y_ = 0.0;
416   float width_ = 1.0;
417   float height_ = 1.0;
418 
419   float r_ = 0.0;
420   float g_ = 0.0;
421   float b_ = 0.0;
422   float a_ = 0.0;
423 };
424 
425 /// Command to probe a data buffer.
426 class ProbeSSBOCommand : public Probe {
427  public:
428   enum class Comparator {
429     kEqual,
430     kNotEqual,
431     kFuzzyEqual,
432     kLess,
433     kLessOrEqual,
434     kGreater,
435     kGreaterOrEqual
436   };
437 
438   explicit ProbeSSBOCommand(Buffer* buffer);
439   ~ProbeSSBOCommand() override;
440 
SetComparator(Comparator comp)441   void SetComparator(Comparator comp) { comparator_ = comp; }
GetComparator()442   Comparator GetComparator() const { return comparator_; }
443 
SetDescriptorSet(uint32_t id)444   void SetDescriptorSet(uint32_t id) { descriptor_set_id_ = id; }
GetDescriptorSet()445   uint32_t GetDescriptorSet() const { return descriptor_set_id_; }
446 
SetBinding(uint32_t id)447   void SetBinding(uint32_t id) { binding_num_ = id; }
GetBinding()448   uint32_t GetBinding() const { return binding_num_; }
449 
SetOffset(uint32_t offset)450   void SetOffset(uint32_t offset) { offset_ = offset; }
GetOffset()451   uint32_t GetOffset() const { return offset_; }
452 
SetFormat(Format * fmt)453   void SetFormat(Format* fmt) { format_ = fmt; }
GetFormat()454   Format* GetFormat() const { return format_; }
455 
SetValues(std::vector<Value> && values)456   void SetValues(std::vector<Value>&& values) { values_ = std::move(values); }
GetValues()457   const std::vector<Value>& GetValues() const { return values_; }
458 
ToString()459   std::string ToString() const override { return "ProbeSSBOCommand"; }
460 
461  private:
462   Comparator comparator_ = Comparator::kEqual;
463   uint32_t descriptor_set_id_ = 0;
464   uint32_t binding_num_ = 0;
465   uint32_t offset_ = 0;
466   Format* format_;
467   std::vector<Value> values_;
468 };
469 
470 /// Base class for BufferCommand and SamplerCommand to handle binding.
471 class BindableResourceCommand : public PipelineCommand {
472  public:
473   BindableResourceCommand(Type type, Pipeline* pipeline);
474   ~BindableResourceCommand() override;
475 
SetDescriptorSet(uint32_t set)476   void SetDescriptorSet(uint32_t set) { descriptor_set_ = set; }
GetDescriptorSet()477   uint32_t GetDescriptorSet() const { return descriptor_set_; }
478 
SetBinding(uint32_t num)479   void SetBinding(uint32_t num) { binding_num_ = num; }
GetBinding()480   uint32_t GetBinding() const { return binding_num_; }
481 
482  private:
483   uint32_t descriptor_set_ = 0;
484   uint32_t binding_num_ = 0;
485 };
486 
487 /// Command to set the size of a buffer, or update a buffers contents.
488 class BufferCommand : public BindableResourceCommand {
489  public:
490   enum class BufferType {
491     kSSBO,
492     kSSBODynamic,
493     kUniform,
494     kUniformDynamic,
495     kPushConstant,
496     kStorageImage,
497     kSampledImage,
498     kCombinedImageSampler,
499     kUniformTexelBuffer,
500     kStorageTexelBuffer
501   };
502 
503   BufferCommand(BufferType type, Pipeline* pipeline);
504   ~BufferCommand() override;
505 
IsSSBO()506   bool IsSSBO() const { return buffer_type_ == BufferType::kSSBO; }
IsSSBODynamic()507   bool IsSSBODynamic() const {
508     return buffer_type_ == BufferType::kSSBODynamic;
509   }
IsUniform()510   bool IsUniform() const { return buffer_type_ == BufferType::kUniform; }
IsUniformDynamic()511   bool IsUniformDynamic() const {
512     return buffer_type_ == BufferType::kUniformDynamic;
513   }
IsStorageImage()514   bool IsStorageImage() const {
515     return buffer_type_ == BufferType::kStorageImage;
516   }
IsSampledImage()517   bool IsSampledImage() const {
518     return buffer_type_ == BufferType::kSampledImage;
519   }
IsCombinedImageSampler()520   bool IsCombinedImageSampler() const {
521     return buffer_type_ == BufferType::kCombinedImageSampler;
522   }
IsUniformTexelBuffer()523   bool IsUniformTexelBuffer() const {
524     return buffer_type_ == BufferType::kUniformTexelBuffer;
525   }
IsStorageTexelBuffer()526   bool IsStorageTexelBuffer() const {
527     return buffer_type_ == BufferType::kStorageTexelBuffer;
528   }
IsPushConstant()529   bool IsPushConstant() const {
530     return buffer_type_ == BufferType::kPushConstant;
531   }
532 
SetIsSubdata()533   void SetIsSubdata() { is_subdata_ = true; }
IsSubdata()534   bool IsSubdata() const { return is_subdata_; }
535 
SetOffset(uint32_t offset)536   void SetOffset(uint32_t offset) { offset_ = offset; }
GetOffset()537   uint32_t GetOffset() const { return offset_; }
538 
SetBaseMipLevel(uint32_t base_mip_level)539   void SetBaseMipLevel(uint32_t base_mip_level) {
540     base_mip_level_ = base_mip_level;
541   }
GetBaseMipLevel()542   uint32_t GetBaseMipLevel() const { return base_mip_level_; }
543 
SetDynamicOffset(uint32_t dynamic_offset)544   void SetDynamicOffset(uint32_t dynamic_offset) {
545     dynamic_offset_ = dynamic_offset;
546   }
GetDynamicOffset()547   uint32_t GetDynamicOffset() const { return dynamic_offset_; }
548 
SetValues(std::vector<Value> && values)549   void SetValues(std::vector<Value>&& values) { values_ = std::move(values); }
GetValues()550   const std::vector<Value>& GetValues() const { return values_; }
551 
SetBuffer(Buffer * buffer)552   void SetBuffer(Buffer* buffer) { buffer_ = buffer; }
GetBuffer()553   Buffer* GetBuffer() const { return buffer_; }
554 
SetSampler(Sampler * sampler)555   void SetSampler(Sampler* sampler) { sampler_ = sampler; }
GetSampler()556   Sampler* GetSampler() const { return sampler_; }
557 
ToString()558   std::string ToString() const override { return "BufferCommand"; }
559 
560  private:
561   Buffer* buffer_ = nullptr;
562   Sampler* sampler_ = nullptr;
563   BufferType buffer_type_;
564   bool is_subdata_ = false;
565   uint32_t offset_ = 0;
566   uint32_t base_mip_level_ = 0;
567   uint32_t dynamic_offset_ = 0;
568   std::vector<Value> values_;
569 };
570 
571 /// Command for setting sampler parameters and binding.
572 class SamplerCommand : public BindableResourceCommand {
573  public:
574   explicit SamplerCommand(Pipeline* pipeline);
575   ~SamplerCommand() override;
576 
SetSampler(Sampler * sampler)577   void SetSampler(Sampler* sampler) { sampler_ = sampler; }
GetSampler()578   Sampler* GetSampler() const { return sampler_; }
579 
ToString()580   std::string ToString() const override { return "SamplerCommand"; }
581 
582  private:
583   Sampler* sampler_ = nullptr;
584 };
585 
586 /// Command to clear the colour attachments.
587 class ClearCommand : public PipelineCommand {
588  public:
589   explicit ClearCommand(Pipeline* pipeline);
590   ~ClearCommand() override;
591 
ToString()592   std::string ToString() const override { return "ClearCommand"; }
593 };
594 
595 /// Command to set the colour for the clear command.
596 class ClearColorCommand : public PipelineCommand {
597  public:
598   explicit ClearColorCommand(Pipeline* pipeline);
599   ~ClearColorCommand() override;
600 
601   // Colours are stored in the range 0.0 - 1.0
SetR(float r)602   void SetR(float r) { r_ = r; }
GetR()603   float GetR() const { return r_; }
604 
SetG(float g)605   void SetG(float g) { g_ = g; }
GetG()606   float GetG() const { return g_; }
607 
SetB(float b)608   void SetB(float b) { b_ = b; }
GetB()609   float GetB() const { return b_; }
610 
SetA(float a)611   void SetA(float a) { a_ = a; }
GetA()612   float GetA() const { return a_; }
613 
ToString()614   std::string ToString() const override { return "ClearColorCommand"; }
615 
616  private:
617   float r_ = 0.0;
618   float g_ = 0.0;
619   float b_ = 0.0;
620   float a_ = 0.0;
621 };
622 
623 /// Command to set the depth value for the clear command.
624 class ClearDepthCommand : public PipelineCommand {
625  public:
626   explicit ClearDepthCommand(Pipeline* pipeline);
627   ~ClearDepthCommand() override;
628 
SetValue(float val)629   void SetValue(float val) { value_ = val; }
GetValue()630   float GetValue() const { return value_; }
631 
ToString()632   std::string ToString() const override { return "ClearDepthCommand"; }
633 
634  private:
635   float value_ = 0.0;
636 };
637 
638 /// Command to set the stencil value for the clear command.
639 class ClearStencilCommand : public PipelineCommand {
640  public:
641   explicit ClearStencilCommand(Pipeline* pipeline);
642   ~ClearStencilCommand() override;
643 
SetValue(uint32_t val)644   void SetValue(uint32_t val) { value_ = val; }
GetValue()645   uint32_t GetValue() const { return value_; }
646 
ToString()647   std::string ToString() const override { return "ClearStencilCommand"; }
648 
649  private:
650   uint32_t value_ = 0;
651 };
652 
653 /// Command to set the patch parameter vertices.
654 class PatchParameterVerticesCommand : public PipelineCommand {
655  public:
656   explicit PatchParameterVerticesCommand(Pipeline* pipeline);
657   ~PatchParameterVerticesCommand() override;
658 
SetControlPointCount(uint32_t count)659   void SetControlPointCount(uint32_t count) { control_point_count_ = count; }
GetControlPointCount()660   uint32_t GetControlPointCount() const { return control_point_count_; }
661 
ToString()662   std::string ToString() const override {
663     return "PatchParameterVerticesCommand";
664   }
665 
666  private:
667   uint32_t control_point_count_ = 0;
668 };
669 
670 /// Command to set the entry point to use for a given shader type.
671 class EntryPointCommand : public PipelineCommand {
672  public:
673   explicit EntryPointCommand(Pipeline* pipeline);
674   ~EntryPointCommand() override;
675 
SetShaderType(ShaderType type)676   void SetShaderType(ShaderType type) { shader_type_ = type; }
GetShaderType()677   ShaderType GetShaderType() const { return shader_type_; }
678 
SetEntryPointName(const std::string & name)679   void SetEntryPointName(const std::string& name) { entry_point_name_ = name; }
GetEntryPointName()680   std::string GetEntryPointName() const { return entry_point_name_; }
681 
ToString()682   std::string ToString() const override { return "EntryPointCommand"; }
683 
684  private:
685   ShaderType shader_type_ = kShaderTypeVertex;
686   std::string entry_point_name_;
687 };
688 
689 /// Command to repeat the given set of commands a number of times.
690 class RepeatCommand : public Command {
691  public:
692   explicit RepeatCommand(uint32_t count);
693   ~RepeatCommand() override;
694 
GetCount()695   uint32_t GetCount() const { return count_; }
696 
SetCommands(std::vector<std::unique_ptr<Command>> cmds)697   void SetCommands(std::vector<std::unique_ptr<Command>> cmds) {
698     commands_ = std::move(cmds);
699   }
700 
GetCommands()701   const std::vector<std::unique_ptr<Command>>& GetCommands() const {
702     return commands_;
703   }
704 
ToString()705   std::string ToString() const override { return "RepeatCommand"; }
706 
707  private:
708   uint32_t count_ = 0;
709   std::vector<std::unique_ptr<Command>> commands_;
710 };
711 
712 }  // namespace amber
713 
714 #endif  // SRC_COMMAND_H_
715