summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2020-12-04 00:45:33 -0800
committerGravatar GitHub2020-12-04 00:45:33 -0800
commitfad38ec6e849a25846f4fd28b61dcfebd6d8af6c (patch)
treef07f5c81a4f959d7859e47b36b3ea1dabc64a850
parentMerge pull request #5061 from lioncash/pessimizing (diff)
parentnode: Mark member functions as [[nodiscard]] where applicable (diff)
downloadyuzu-fad38ec6e849a25846f4fd28b61dcfebd6d8af6c.tar.gz
yuzu-fad38ec6e849a25846f4fd28b61dcfebd6d8af6c.tar.xz
yuzu-fad38ec6e849a25846f4fd28b61dcfebd6d8af6c.zip
Merge pull request #5064 from lioncash/node-shadow
node: Eliminate variable shadowing
-rw-r--r--src/video_core/shader/node.h152
1 files changed, 77 insertions, 75 deletions
diff --git a/src/video_core/shader/node.h b/src/video_core/shader/node.h
index 8f230d57a..a1e2c4d8e 100644
--- a/src/video_core/shader/node.h
+++ b/src/video_core/shader/node.h
@@ -284,24 +284,26 @@ using TrackSampler = std::shared_ptr<TrackSamplerData>;
284 284
285struct Sampler { 285struct Sampler {
286 /// Bound samplers constructor 286 /// Bound samplers constructor
287 constexpr explicit Sampler(u32 index, u32 offset, Tegra::Shader::TextureType type, 287 constexpr explicit Sampler(u32 index_, u32 offset_, Tegra::Shader::TextureType type_,
288 bool is_array, bool is_shadow, bool is_buffer, bool is_indexed) 288 bool is_array_, bool is_shadow_, bool is_buffer_, bool is_indexed_)
289 : index{index}, offset{offset}, type{type}, is_array{is_array}, is_shadow{is_shadow}, 289 : index{index_}, offset{offset_}, type{type_}, is_array{is_array_}, is_shadow{is_shadow_},
290 is_buffer{is_buffer}, is_indexed{is_indexed} {} 290 is_buffer{is_buffer_}, is_indexed{is_indexed_} {}
291 291
292 /// Separate sampler constructor 292 /// Separate sampler constructor
293 constexpr explicit Sampler(u32 index, std::pair<u32, u32> offsets, std::pair<u32, u32> buffers, 293 constexpr explicit Sampler(u32 index_, std::pair<u32, u32> offsets, std::pair<u32, u32> buffers,
294 Tegra::Shader::TextureType type, bool is_array, bool is_shadow, 294 Tegra::Shader::TextureType type, bool is_array_, bool is_shadow_,
295 bool is_buffer) 295 bool is_buffer_)
296 : index{index}, offset{offsets.first}, secondary_offset{offsets.second}, 296 : index{index_}, offset{offsets.first}, secondary_offset{offsets.second},
297 buffer{buffers.first}, secondary_buffer{buffers.second}, type{type}, is_array{is_array}, 297 buffer{buffers.first}, secondary_buffer{buffers.second}, type{type}, is_array{is_array_},
298 is_shadow{is_shadow}, is_buffer{is_buffer}, is_separated{true} {} 298 is_shadow{is_shadow_}, is_buffer{is_buffer_}, is_separated{true} {}
299 299
300 /// Bindless samplers constructor 300 /// Bindless samplers constructor
301 constexpr explicit Sampler(u32 index, u32 offset, u32 buffer, Tegra::Shader::TextureType type, 301 constexpr explicit Sampler(u32 index_, u32 offset_, u32 buffer_,
302 bool is_array, bool is_shadow, bool is_buffer, bool is_indexed) 302 Tegra::Shader::TextureType type, bool is_array_, bool is_shadow_,
303 : index{index}, offset{offset}, buffer{buffer}, type{type}, is_array{is_array}, 303 bool is_buffer_, bool is_indexed_)
304 is_shadow{is_shadow}, is_buffer{is_buffer}, is_bindless{true}, is_indexed{is_indexed} {} 304 : index{index_}, offset{offset_}, buffer{buffer_}, type{type}, is_array{is_array_},
305 is_shadow{is_shadow_}, is_buffer{is_buffer_}, is_bindless{true}, is_indexed{is_indexed_} {
306 }
305 307
306 u32 index = 0; ///< Emulated index given for the this sampler. 308 u32 index = 0; ///< Emulated index given for the this sampler.
307 u32 offset = 0; ///< Offset in the const buffer from where the sampler is being read. 309 u32 offset = 0; ///< Offset in the const buffer from where the sampler is being read.
@@ -341,12 +343,12 @@ struct BindlessSamplerNode {
341struct Image { 343struct Image {
342public: 344public:
343 /// Bound images constructor 345 /// Bound images constructor
344 constexpr explicit Image(u32 index, u32 offset, Tegra::Shader::ImageType type) 346 constexpr explicit Image(u32 index_, u32 offset_, Tegra::Shader::ImageType type_)
345 : index{index}, offset{offset}, type{type} {} 347 : index{index_}, offset{offset_}, type{type_} {}
346 348
347 /// Bindless samplers constructor 349 /// Bindless samplers constructor
348 constexpr explicit Image(u32 index, u32 offset, u32 buffer, Tegra::Shader::ImageType type) 350 constexpr explicit Image(u32 index_, u32 offset_, u32 buffer_, Tegra::Shader::ImageType type_)
349 : index{index}, offset{offset}, buffer{buffer}, type{type}, is_bindless{true} {} 351 : index{index_}, offset{offset_}, buffer{buffer_}, type{type_}, is_bindless{true} {}
350 352
351 void MarkWrite() { 353 void MarkWrite() {
352 is_written = true; 354 is_written = true;
@@ -377,7 +379,7 @@ struct GlobalMemoryBase {
377 u32 cbuf_index = 0; 379 u32 cbuf_index = 0;
378 u32 cbuf_offset = 0; 380 u32 cbuf_offset = 0;
379 381
380 bool operator<(const GlobalMemoryBase& rhs) const { 382 [[nodiscard]] bool operator<(const GlobalMemoryBase& rhs) const {
381 return std::tie(cbuf_index, cbuf_offset) < std::tie(rhs.cbuf_index, rhs.cbuf_offset); 383 return std::tie(cbuf_index, cbuf_offset) < std::tie(rhs.cbuf_index, rhs.cbuf_offset);
382 } 384 }
383}; 385};
@@ -414,7 +416,7 @@ using Meta =
414 416
415class AmendNode { 417class AmendNode {
416public: 418public:
417 std::optional<std::size_t> GetAmendIndex() const { 419 [[nodiscard]] std::optional<std::size_t> GetAmendIndex() const {
418 if (amend_index == amend_null_index) { 420 if (amend_index == amend_null_index) {
419 return std::nullopt; 421 return std::nullopt;
420 } 422 }
@@ -437,34 +439,34 @@ private:
437/// Holds any kind of operation that can be done in the IR 439/// Holds any kind of operation that can be done in the IR
438class OperationNode final : public AmendNode { 440class OperationNode final : public AmendNode {
439public: 441public:
440 explicit OperationNode(OperationCode code) : OperationNode(code, Meta{}) {} 442 explicit OperationNode(OperationCode code_) : OperationNode(code_, Meta{}) {}
441 443
442 explicit OperationNode(OperationCode code, Meta meta) 444 explicit OperationNode(OperationCode code_, Meta meta_)
443 : OperationNode(code, std::move(meta), std::vector<Node>{}) {} 445 : OperationNode(code_, std::move(meta_), std::vector<Node>{}) {}
444 446
445 explicit OperationNode(OperationCode code, std::vector<Node> operands) 447 explicit OperationNode(OperationCode code_, std::vector<Node> operands_)
446 : OperationNode(code, Meta{}, std::move(operands)) {} 448 : OperationNode(code_, Meta{}, std::move(operands_)) {}
447 449
448 explicit OperationNode(OperationCode code, Meta meta, std::vector<Node> operands) 450 explicit OperationNode(OperationCode code_, Meta meta_, std::vector<Node> operands_)
449 : code{code}, meta{std::move(meta)}, operands{std::move(operands)} {} 451 : code{code_}, meta{std::move(meta_)}, operands{std::move(operands_)} {}
450 452
451 template <typename... Args> 453 template <typename... Args>
452 explicit OperationNode(OperationCode code, Meta meta, Args&&... operands) 454 explicit OperationNode(OperationCode code_, Meta meta_, Args&&... operands_)
453 : code{code}, meta{std::move(meta)}, operands{operands...} {} 455 : code{code_}, meta{std::move(meta_)}, operands{operands_...} {}
454 456
455 OperationCode GetCode() const { 457 [[nodiscard]] OperationCode GetCode() const {
456 return code; 458 return code;
457 } 459 }
458 460
459 const Meta& GetMeta() const { 461 [[nodiscard]] const Meta& GetMeta() const {
460 return meta; 462 return meta;
461 } 463 }
462 464
463 std::size_t GetOperandsCount() const { 465 [[nodiscard]] std::size_t GetOperandsCount() const {
464 return operands.size(); 466 return operands.size();
465 } 467 }
466 468
467 const Node& operator[](std::size_t operand_index) const { 469 [[nodiscard]] const Node& operator[](std::size_t operand_index) const {
468 return operands.at(operand_index); 470 return operands.at(operand_index);
469 } 471 }
470 472
@@ -477,14 +479,14 @@ private:
477/// Encloses inside any kind of node that returns a boolean conditionally-executed code 479/// Encloses inside any kind of node that returns a boolean conditionally-executed code
478class ConditionalNode final : public AmendNode { 480class ConditionalNode final : public AmendNode {
479public: 481public:
480 explicit ConditionalNode(Node condition, std::vector<Node>&& code) 482 explicit ConditionalNode(Node condition_, std::vector<Node>&& code_)
481 : condition{std::move(condition)}, code{std::move(code)} {} 483 : condition{std::move(condition_)}, code{std::move(code_)} {}
482 484
483 const Node& GetCondition() const { 485 [[nodiscard]] const Node& GetCondition() const {
484 return condition; 486 return condition;
485 } 487 }
486 488
487 const std::vector<Node>& GetCode() const { 489 [[nodiscard]] const std::vector<Node>& GetCode() const {
488 return code; 490 return code;
489 } 491 }
490 492
@@ -496,9 +498,9 @@ private:
496/// A general purpose register 498/// A general purpose register
497class GprNode final { 499class GprNode final {
498public: 500public:
499 explicit constexpr GprNode(Tegra::Shader::Register index) : index{index} {} 501 explicit constexpr GprNode(Tegra::Shader::Register index_) : index{index_} {}
500 502
501 u32 GetIndex() const { 503 [[nodiscard]] constexpr u32 GetIndex() const {
502 return static_cast<u32>(index); 504 return static_cast<u32>(index);
503 } 505 }
504 506
@@ -509,9 +511,9 @@ private:
509/// A custom variable 511/// A custom variable
510class CustomVarNode final { 512class CustomVarNode final {
511public: 513public:
512 explicit constexpr CustomVarNode(u32 index) : index{index} {} 514 explicit constexpr CustomVarNode(u32 index_) : index{index_} {}
513 515
514 constexpr u32 GetIndex() const { 516 [[nodiscard]] constexpr u32 GetIndex() const {
515 return index; 517 return index;
516 } 518 }
517 519
@@ -522,9 +524,9 @@ private:
522/// A 32-bits value that represents an immediate value 524/// A 32-bits value that represents an immediate value
523class ImmediateNode final { 525class ImmediateNode final {
524public: 526public:
525 explicit constexpr ImmediateNode(u32 value) : value{value} {} 527 explicit constexpr ImmediateNode(u32 value_) : value{value_} {}
526 528
527 u32 GetValue() const { 529 [[nodiscard]] constexpr u32 GetValue() const {
528 return value; 530 return value;
529 } 531 }
530 532
@@ -535,9 +537,9 @@ private:
535/// One of Maxwell's internal flags 537/// One of Maxwell's internal flags
536class InternalFlagNode final { 538class InternalFlagNode final {
537public: 539public:
538 explicit constexpr InternalFlagNode(InternalFlag flag) : flag{flag} {} 540 explicit constexpr InternalFlagNode(InternalFlag flag_) : flag{flag_} {}
539 541
540 InternalFlag GetFlag() const { 542 [[nodiscard]] constexpr InternalFlag GetFlag() const {
541 return flag; 543 return flag;
542 } 544 }
543 545
@@ -548,14 +550,14 @@ private:
548/// A predicate register, it can be negated without additional nodes 550/// A predicate register, it can be negated without additional nodes
549class PredicateNode final { 551class PredicateNode final {
550public: 552public:
551 explicit constexpr PredicateNode(Tegra::Shader::Pred index, bool negated) 553 explicit constexpr PredicateNode(Tegra::Shader::Pred index_, bool negated_)
552 : index{index}, negated{negated} {} 554 : index{index_}, negated{negated_} {}
553 555
554 Tegra::Shader::Pred GetIndex() const { 556 [[nodiscard]] constexpr Tegra::Shader::Pred GetIndex() const {
555 return index; 557 return index;
556 } 558 }
557 559
558 bool IsNegated() const { 560 [[nodiscard]] constexpr bool IsNegated() const {
559 return negated; 561 return negated;
560 } 562 }
561 563
@@ -568,30 +570,30 @@ private:
568class AbufNode final { 570class AbufNode final {
569public: 571public:
570 // Initialize for standard attributes (index is explicit). 572 // Initialize for standard attributes (index is explicit).
571 explicit AbufNode(Tegra::Shader::Attribute::Index index, u32 element, Node buffer = {}) 573 explicit AbufNode(Tegra::Shader::Attribute::Index index_, u32 element_, Node buffer_ = {})
572 : buffer{std::move(buffer)}, index{index}, element{element} {} 574 : buffer{std::move(buffer_)}, index{index_}, element{element_} {}
573 575
574 // Initialize for physical attributes (index is a variable value). 576 // Initialize for physical attributes (index is a variable value).
575 explicit AbufNode(Node physical_address, Node buffer = {}) 577 explicit AbufNode(Node physical_address_, Node buffer_ = {})
576 : physical_address{std::move(physical_address)}, buffer{std::move(buffer)} {} 578 : physical_address{std::move(physical_address_)}, buffer{std::move(buffer_)} {}
577 579
578 Tegra::Shader::Attribute::Index GetIndex() const { 580 [[nodiscard]] Tegra::Shader::Attribute::Index GetIndex() const {
579 return index; 581 return index;
580 } 582 }
581 583
582 u32 GetElement() const { 584 [[nodiscard]] u32 GetElement() const {
583 return element; 585 return element;
584 } 586 }
585 587
586 const Node& GetBuffer() const { 588 [[nodiscard]] const Node& GetBuffer() const {
587 return buffer; 589 return buffer;
588 } 590 }
589 591
590 bool IsPhysicalBuffer() const { 592 [[nodiscard]] bool IsPhysicalBuffer() const {
591 return static_cast<bool>(physical_address); 593 return static_cast<bool>(physical_address);
592 } 594 }
593 595
594 const Node& GetPhysicalAddress() const { 596 [[nodiscard]] const Node& GetPhysicalAddress() const {
595 return physical_address; 597 return physical_address;
596 } 598 }
597 599
@@ -605,9 +607,9 @@ private:
605/// Patch memory (used to communicate tessellation stages). 607/// Patch memory (used to communicate tessellation stages).
606class PatchNode final { 608class PatchNode final {
607public: 609public:
608 explicit PatchNode(u32 offset) : offset{offset} {} 610 explicit constexpr PatchNode(u32 offset_) : offset{offset_} {}
609 611
610 u32 GetOffset() const { 612 [[nodiscard]] constexpr u32 GetOffset() const {
611 return offset; 613 return offset;
612 } 614 }
613 615
@@ -618,13 +620,13 @@ private:
618/// Constant buffer node, usually mapped to uniform buffers in GLSL 620/// Constant buffer node, usually mapped to uniform buffers in GLSL
619class CbufNode final { 621class CbufNode final {
620public: 622public:
621 explicit CbufNode(u32 index, Node offset) : index{index}, offset{std::move(offset)} {} 623 explicit CbufNode(u32 index_, Node offset_) : index{index_}, offset{std::move(offset_)} {}
622 624
623 u32 GetIndex() const { 625 [[nodiscard]] u32 GetIndex() const {
624 return index; 626 return index;
625 } 627 }
626 628
627 const Node& GetOffset() const { 629 [[nodiscard]] const Node& GetOffset() const {
628 return offset; 630 return offset;
629 } 631 }
630 632
@@ -636,9 +638,9 @@ private:
636/// Local memory node 638/// Local memory node
637class LmemNode final { 639class LmemNode final {
638public: 640public:
639 explicit LmemNode(Node address) : address{std::move(address)} {} 641 explicit LmemNode(Node address_) : address{std::move(address_)} {}
640 642
641 const Node& GetAddress() const { 643 [[nodiscard]] const Node& GetAddress() const {
642 return address; 644 return address;
643 } 645 }
644 646
@@ -649,9 +651,9 @@ private:
649/// Shared memory node 651/// Shared memory node
650class SmemNode final { 652class SmemNode final {
651public: 653public:
652 explicit SmemNode(Node address) : address{std::move(address)} {} 654 explicit SmemNode(Node address_) : address{std::move(address_)} {}
653 655
654 const Node& GetAddress() const { 656 [[nodiscard]] const Node& GetAddress() const {
655 return address; 657 return address;
656 } 658 }
657 659
@@ -662,19 +664,19 @@ private:
662/// Global memory node 664/// Global memory node
663class GmemNode final { 665class GmemNode final {
664public: 666public:
665 explicit GmemNode(Node real_address, Node base_address, const GlobalMemoryBase& descriptor) 667 explicit GmemNode(Node real_address_, Node base_address_, const GlobalMemoryBase& descriptor_)
666 : real_address{std::move(real_address)}, base_address{std::move(base_address)}, 668 : real_address{std::move(real_address_)}, base_address{std::move(base_address_)},
667 descriptor{descriptor} {} 669 descriptor{descriptor_} {}
668 670
669 const Node& GetRealAddress() const { 671 [[nodiscard]] const Node& GetRealAddress() const {
670 return real_address; 672 return real_address;
671 } 673 }
672 674
673 const Node& GetBaseAddress() const { 675 [[nodiscard]] const Node& GetBaseAddress() const {
674 return base_address; 676 return base_address;
675 } 677 }
676 678
677 const GlobalMemoryBase& GetDescriptor() const { 679 [[nodiscard]] const GlobalMemoryBase& GetDescriptor() const {
678 return descriptor; 680 return descriptor;
679 } 681 }
680 682
@@ -687,9 +689,9 @@ private:
687/// Commentary, can be dropped 689/// Commentary, can be dropped
688class CommentNode final { 690class CommentNode final {
689public: 691public:
690 explicit CommentNode(std::string text) : text{std::move(text)} {} 692 explicit CommentNode(std::string text_) : text{std::move(text_)} {}
691 693
692 const std::string& GetText() const { 694 [[nodiscard]] const std::string& GetText() const {
693 return text; 695 return text;
694 } 696 }
695 697