• 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_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 
SetDescriptorOffset(uint64_t descriptor_offset)549   void SetDescriptorOffset(uint64_t descriptor_offset) {
550     descriptor_offset_ = descriptor_offset;
551   }
GetDescriptorOffset()552   uint64_t GetDescriptorOffset() const { return descriptor_offset_; }
553 
SetDescriptorRange(uint64_t descriptor_range)554   void SetDescriptorRange(uint64_t descriptor_range) {
555     descriptor_range_ = descriptor_range;
556   }
GetDescriptorRange()557   uint64_t GetDescriptorRange() const { return descriptor_range_; }
558 
SetValues(std::vector<Value> && values)559   void SetValues(std::vector<Value>&& values) { values_ = std::move(values); }
GetValues()560   const std::vector<Value>& GetValues() const { return values_; }
561 
SetBuffer(Buffer * buffer)562   void SetBuffer(Buffer* buffer) { buffer_ = buffer; }
GetBuffer()563   Buffer* GetBuffer() const { return buffer_; }
564 
SetSampler(Sampler * sampler)565   void SetSampler(Sampler* sampler) { sampler_ = sampler; }
GetSampler()566   Sampler* GetSampler() const { return sampler_; }
567 
ToString()568   std::string ToString() const override { return "BufferCommand"; }
569 
570  private:
571   Buffer* buffer_ = nullptr;
572   Sampler* sampler_ = nullptr;
573   BufferType buffer_type_;
574   bool is_subdata_ = false;
575   uint32_t offset_ = 0;
576   uint32_t base_mip_level_ = 0;
577   uint32_t dynamic_offset_ = 0;
578   uint64_t descriptor_offset_ = 0;
579   uint64_t descriptor_range_ = ~0ULL;
580   std::vector<Value> values_;
581 };
582 
583 /// Command for setting sampler parameters and binding.
584 class SamplerCommand : public BindableResourceCommand {
585  public:
586   explicit SamplerCommand(Pipeline* pipeline);
587   ~SamplerCommand() override;
588 
SetSampler(Sampler * sampler)589   void SetSampler(Sampler* sampler) { sampler_ = sampler; }
GetSampler()590   Sampler* GetSampler() const { return sampler_; }
591 
ToString()592   std::string ToString() const override { return "SamplerCommand"; }
593 
594  private:
595   Sampler* sampler_ = nullptr;
596 };
597 
598 /// Command to clear the colour attachments.
599 class ClearCommand : public PipelineCommand {
600  public:
601   explicit ClearCommand(Pipeline* pipeline);
602   ~ClearCommand() override;
603 
ToString()604   std::string ToString() const override { return "ClearCommand"; }
605 };
606 
607 /// Command to set the colour for the clear command.
608 class ClearColorCommand : public PipelineCommand {
609  public:
610   explicit ClearColorCommand(Pipeline* pipeline);
611   ~ClearColorCommand() override;
612 
613   // Colours are stored in the range 0.0 - 1.0
SetR(float r)614   void SetR(float r) { r_ = r; }
GetR()615   float GetR() const { return r_; }
616 
SetG(float g)617   void SetG(float g) { g_ = g; }
GetG()618   float GetG() const { return g_; }
619 
SetB(float b)620   void SetB(float b) { b_ = b; }
GetB()621   float GetB() const { return b_; }
622 
SetA(float a)623   void SetA(float a) { a_ = a; }
GetA()624   float GetA() const { return a_; }
625 
ToString()626   std::string ToString() const override { return "ClearColorCommand"; }
627 
628  private:
629   float r_ = 0.0;
630   float g_ = 0.0;
631   float b_ = 0.0;
632   float a_ = 0.0;
633 };
634 
635 /// Command to set the depth value for the clear command.
636 class ClearDepthCommand : public PipelineCommand {
637  public:
638   explicit ClearDepthCommand(Pipeline* pipeline);
639   ~ClearDepthCommand() override;
640 
SetValue(float val)641   void SetValue(float val) { value_ = val; }
GetValue()642   float GetValue() const { return value_; }
643 
ToString()644   std::string ToString() const override { return "ClearDepthCommand"; }
645 
646  private:
647   float value_ = 0.0;
648 };
649 
650 /// Command to set the stencil value for the clear command.
651 class ClearStencilCommand : public PipelineCommand {
652  public:
653   explicit ClearStencilCommand(Pipeline* pipeline);
654   ~ClearStencilCommand() override;
655 
SetValue(uint32_t val)656   void SetValue(uint32_t val) { value_ = val; }
GetValue()657   uint32_t GetValue() const { return value_; }
658 
ToString()659   std::string ToString() const override { return "ClearStencilCommand"; }
660 
661  private:
662   uint32_t value_ = 0;
663 };
664 
665 /// Command to set the patch parameter vertices.
666 class PatchParameterVerticesCommand : public PipelineCommand {
667  public:
668   explicit PatchParameterVerticesCommand(Pipeline* pipeline);
669   ~PatchParameterVerticesCommand() override;
670 
SetControlPointCount(uint32_t count)671   void SetControlPointCount(uint32_t count) { control_point_count_ = count; }
GetControlPointCount()672   uint32_t GetControlPointCount() const { return control_point_count_; }
673 
ToString()674   std::string ToString() const override {
675     return "PatchParameterVerticesCommand";
676   }
677 
678  private:
679   uint32_t control_point_count_ = 0;
680 };
681 
682 /// Command to set the entry point to use for a given shader type.
683 class EntryPointCommand : public PipelineCommand {
684  public:
685   explicit EntryPointCommand(Pipeline* pipeline);
686   ~EntryPointCommand() override;
687 
SetShaderType(ShaderType type)688   void SetShaderType(ShaderType type) { shader_type_ = type; }
GetShaderType()689   ShaderType GetShaderType() const { return shader_type_; }
690 
SetEntryPointName(const std::string & name)691   void SetEntryPointName(const std::string& name) { entry_point_name_ = name; }
GetEntryPointName()692   std::string GetEntryPointName() const { return entry_point_name_; }
693 
ToString()694   std::string ToString() const override { return "EntryPointCommand"; }
695 
696  private:
697   ShaderType shader_type_ = kShaderTypeVertex;
698   std::string entry_point_name_;
699 };
700 
701 /// Command to repeat the given set of commands a number of times.
702 class RepeatCommand : public Command {
703  public:
704   explicit RepeatCommand(uint32_t count);
705   ~RepeatCommand() override;
706 
GetCount()707   uint32_t GetCount() const { return count_; }
708 
SetCommands(std::vector<std::unique_ptr<Command>> cmds)709   void SetCommands(std::vector<std::unique_ptr<Command>> cmds) {
710     commands_ = std::move(cmds);
711   }
712 
GetCommands()713   const std::vector<std::unique_ptr<Command>>& GetCommands() const {
714     return commands_;
715   }
716 
ToString()717   std::string ToString() const override { return "RepeatCommand"; }
718 
719  private:
720   uint32_t count_ = 0;
721   std::vector<std::unique_ptr<Command>> commands_;
722 };
723 
724 }  // namespace amber
725 
726 #endif  // SRC_COMMAND_H_
727