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