diff options
| author | 2019-06-06 20:01:28 -0300 | |
|---|---|---|
| committer | 2019-06-06 20:03:33 -0300 | |
| commit | 769a50661a90f06aa660419d869e266abcddf9f3 (patch) | |
| tree | a2580211624e0c198b732b94b6c5379ccaaefd22 | |
| parent | shader: Move Node declarations out of the shader IR header (diff) | |
| download | yuzu-769a50661a90f06aa660419d869e266abcddf9f3.tar.gz yuzu-769a50661a90f06aa660419d869e266abcddf9f3.tar.xz yuzu-769a50661a90f06aa660419d869e266abcddf9f3.zip | |
shader/node: Minor changes
Reflect std::shared_ptr nature of Node on initializers and remove
constant members in nodes.
Add some commentaries.
| -rw-r--r-- | src/video_core/shader/node.h | 104 |
1 files changed, 54 insertions, 50 deletions
diff --git a/src/video_core/shader/node.h b/src/video_core/shader/node.h index 1e7a5f699..c002f90f9 100644 --- a/src/video_core/shader/node.h +++ b/src/video_core/shader/node.h | |||
| @@ -18,25 +18,6 @@ | |||
| 18 | 18 | ||
| 19 | namespace VideoCommon::Shader { | 19 | namespace VideoCommon::Shader { |
| 20 | 20 | ||
| 21 | class OperationNode; | ||
| 22 | class ConditionalNode; | ||
| 23 | class GprNode; | ||
| 24 | class ImmediateNode; | ||
| 25 | class InternalFlagNode; | ||
| 26 | class PredicateNode; | ||
| 27 | class AbufNode; ///< Attribute buffer | ||
| 28 | class CbufNode; ///< Constant buffer | ||
| 29 | class LmemNode; ///< Local memory | ||
| 30 | class GmemNode; ///< Global memory | ||
| 31 | class CommentNode; | ||
| 32 | |||
| 33 | using NodeData = | ||
| 34 | std::variant<OperationNode, ConditionalNode, GprNode, ImmediateNode, InternalFlagNode, | ||
| 35 | PredicateNode, AbufNode, CbufNode, LmemNode, GmemNode, CommentNode>; | ||
| 36 | using Node = std::shared_ptr<NodeData>; | ||
| 37 | using Node4 = std::array<Node, 4>; | ||
| 38 | using NodeBlock = std::vector<Node>; | ||
| 39 | |||
| 40 | enum class OperationCode { | 21 | enum class OperationCode { |
| 41 | Assign, /// (float& dest, float src) -> void | 22 | Assign, /// (float& dest, float src) -> void |
| 42 | 23 | ||
| @@ -193,21 +174,40 @@ enum class InternalFlag { | |||
| 193 | Amount = 4, | 174 | Amount = 4, |
| 194 | }; | 175 | }; |
| 195 | 176 | ||
| 177 | class OperationNode; | ||
| 178 | class ConditionalNode; | ||
| 179 | class GprNode; | ||
| 180 | class ImmediateNode; | ||
| 181 | class InternalFlagNode; | ||
| 182 | class PredicateNode; | ||
| 183 | class AbufNode; | ||
| 184 | class CbufNode; | ||
| 185 | class LmemNode; | ||
| 186 | class GmemNode; | ||
| 187 | class CommentNode; | ||
| 188 | |||
| 189 | using NodeData = | ||
| 190 | std::variant<OperationNode, ConditionalNode, GprNode, ImmediateNode, InternalFlagNode, | ||
| 191 | PredicateNode, AbufNode, CbufNode, LmemNode, GmemNode, CommentNode>; | ||
| 192 | using Node = std::shared_ptr<NodeData>; | ||
| 193 | using Node4 = std::array<Node, 4>; | ||
| 194 | using NodeBlock = std::vector<Node>; | ||
| 195 | |||
| 196 | class Sampler { | 196 | class Sampler { |
| 197 | public: | 197 | public: |
| 198 | // Use this constructor for bounded Samplers | 198 | /// This constructor is for bound samplers |
| 199 | explicit Sampler(std::size_t offset, std::size_t index, Tegra::Shader::TextureType type, | 199 | explicit Sampler(std::size_t offset, std::size_t index, Tegra::Shader::TextureType type, |
| 200 | bool is_array, bool is_shadow) | 200 | bool is_array, bool is_shadow) |
| 201 | : offset{offset}, index{index}, type{type}, is_array{is_array}, is_shadow{is_shadow}, | 201 | : offset{offset}, index{index}, type{type}, is_array{is_array}, is_shadow{is_shadow}, |
| 202 | is_bindless{false} {} | 202 | is_bindless{false} {} |
| 203 | 203 | ||
| 204 | // Use this constructor for bindless Samplers | 204 | /// This constructor is for bindless samplers |
| 205 | explicit Sampler(u32 cbuf_index, u32 cbuf_offset, std::size_t index, | 205 | explicit Sampler(u32 cbuf_index, u32 cbuf_offset, std::size_t index, |
| 206 | Tegra::Shader::TextureType type, bool is_array, bool is_shadow) | 206 | Tegra::Shader::TextureType type, bool is_array, bool is_shadow) |
| 207 | : offset{(static_cast<u64>(cbuf_index) << 32) | cbuf_offset}, index{index}, type{type}, | 207 | : offset{(static_cast<u64>(cbuf_index) << 32) | cbuf_offset}, index{index}, type{type}, |
| 208 | is_array{is_array}, is_shadow{is_shadow}, is_bindless{true} {} | 208 | is_array{is_array}, is_shadow{is_shadow}, is_bindless{true} {} |
| 209 | 209 | ||
| 210 | // Use this only for serialization/deserialization | 210 | /// This constructor is for serialization/deserialization |
| 211 | explicit Sampler(std::size_t offset, std::size_t index, Tegra::Shader::TextureType type, | 211 | explicit Sampler(std::size_t offset, std::size_t index, Tegra::Shader::TextureType type, |
| 212 | bool is_array, bool is_shadow, bool is_bindless) | 212 | bool is_array, bool is_shadow, bool is_bindless) |
| 213 | : offset{offset}, index{index}, type{type}, is_array{is_array}, is_shadow{is_shadow}, | 213 | : offset{offset}, index{index}, type{type}, is_array{is_array}, is_shadow{is_shadow}, |
| @@ -267,21 +267,24 @@ struct GlobalMemoryBase { | |||
| 267 | } | 267 | } |
| 268 | }; | 268 | }; |
| 269 | 269 | ||
| 270 | /// Parameters describing an arithmetic operation | ||
| 270 | struct MetaArithmetic { | 271 | struct MetaArithmetic { |
| 271 | bool precise{}; | 272 | bool precise{}; ///< Whether the operation can be constraint or not |
| 272 | }; | 273 | }; |
| 273 | 274 | ||
| 275 | /// Parameters describing a texture sampler | ||
| 274 | struct MetaTexture { | 276 | struct MetaTexture { |
| 275 | const Sampler& sampler; | 277 | const Sampler& sampler; |
| 276 | Node array{}; | 278 | Node array; |
| 277 | Node depth_compare{}; | 279 | Node depth_compare; |
| 278 | std::vector<Node> aoffi; | 280 | std::vector<Node> aoffi; |
| 279 | Node bias{}; | 281 | Node bias; |
| 280 | Node lod{}; | 282 | Node lod; |
| 281 | Node component{}; | 283 | Node component{}; |
| 282 | u32 element{}; | 284 | u32 element{}; |
| 283 | }; | 285 | }; |
| 284 | 286 | ||
| 287 | /// Parameters that modify an operation but are not part of any particular operand | ||
| 285 | using Meta = std::variant<MetaArithmetic, MetaTexture, Tegra::Shader::HalfType>; | 288 | using Meta = std::variant<MetaArithmetic, MetaTexture, Tegra::Shader::HalfType>; |
| 286 | 289 | ||
| 287 | /// Holds any kind of operation that can be done in the IR | 290 | /// Holds any kind of operation that can be done in the IR |
| @@ -328,9 +331,9 @@ private: | |||
| 328 | class ConditionalNode final { | 331 | class ConditionalNode final { |
| 329 | public: | 332 | public: |
| 330 | explicit ConditionalNode(Node condition, std::vector<Node>&& code) | 333 | explicit ConditionalNode(Node condition, std::vector<Node>&& code) |
| 331 | : condition{condition}, code{std::move(code)} {} | 334 | : condition{std::move(condition)}, code{std::move(code)} {} |
| 332 | 335 | ||
| 333 | Node GetCondition() const { | 336 | const Node& GetCondition() const { |
| 334 | return condition; | 337 | return condition; |
| 335 | } | 338 | } |
| 336 | 339 | ||
| @@ -339,7 +342,7 @@ public: | |||
| 339 | } | 342 | } |
| 340 | 343 | ||
| 341 | private: | 344 | private: |
| 342 | const Node condition; ///< Condition to be satisfied | 345 | Node condition; ///< Condition to be satisfied |
| 343 | std::vector<Node> code; ///< Code to execute | 346 | std::vector<Node> code; ///< Code to execute |
| 344 | }; | 347 | }; |
| 345 | 348 | ||
| @@ -353,7 +356,7 @@ public: | |||
| 353 | } | 356 | } |
| 354 | 357 | ||
| 355 | private: | 358 | private: |
| 356 | const Tegra::Shader::Register index; | 359 | Tegra::Shader::Register index{}; |
| 357 | }; | 360 | }; |
| 358 | 361 | ||
| 359 | /// A 32-bits value that represents an immediate value | 362 | /// A 32-bits value that represents an immediate value |
| @@ -366,7 +369,7 @@ public: | |||
| 366 | } | 369 | } |
| 367 | 370 | ||
| 368 | private: | 371 | private: |
| 369 | const u32 value; | 372 | u32 value{}; |
| 370 | }; | 373 | }; |
| 371 | 374 | ||
| 372 | /// One of Maxwell's internal flags | 375 | /// One of Maxwell's internal flags |
| @@ -379,7 +382,7 @@ public: | |||
| 379 | } | 382 | } |
| 380 | 383 | ||
| 381 | private: | 384 | private: |
| 382 | const InternalFlag flag; | 385 | InternalFlag flag{}; |
| 383 | }; | 386 | }; |
| 384 | 387 | ||
| 385 | /// A predicate register, it can be negated without additional nodes | 388 | /// A predicate register, it can be negated without additional nodes |
| @@ -397,8 +400,8 @@ public: | |||
| 397 | } | 400 | } |
| 398 | 401 | ||
| 399 | private: | 402 | private: |
| 400 | const Tegra::Shader::Pred index; | 403 | Tegra::Shader::Pred index{}; |
| 401 | const bool negated; | 404 | bool negated{}; |
| 402 | }; | 405 | }; |
| 403 | 406 | ||
| 404 | /// Attribute buffer memory (known as attributes or varyings in GLSL terms) | 407 | /// Attribute buffer memory (known as attributes or varyings in GLSL terms) |
| @@ -410,7 +413,7 @@ public: | |||
| 410 | 413 | ||
| 411 | // Initialize for physical attributes (index is a variable value). | 414 | // Initialize for physical attributes (index is a variable value). |
| 412 | explicit AbufNode(Node physical_address, Node buffer = {}) | 415 | explicit AbufNode(Node physical_address, Node buffer = {}) |
| 413 | : physical_address{physical_address}, buffer{std::move(buffer)} {} | 416 | : physical_address{std::move(physical_address)}, buffer{std::move(buffer)} {} |
| 414 | 417 | ||
| 415 | Tegra::Shader::Attribute::Index GetIndex() const { | 418 | Tegra::Shader::Attribute::Index GetIndex() const { |
| 416 | return index; | 419 | return index; |
| @@ -420,7 +423,7 @@ public: | |||
| 420 | return element; | 423 | return element; |
| 421 | } | 424 | } |
| 422 | 425 | ||
| 423 | Node GetBuffer() const { | 426 | const Node& GetBuffer() const { |
| 424 | return buffer; | 427 | return buffer; |
| 425 | } | 428 | } |
| 426 | 429 | ||
| @@ -442,45 +445,46 @@ private: | |||
| 442 | /// Constant buffer node, usually mapped to uniform buffers in GLSL | 445 | /// Constant buffer node, usually mapped to uniform buffers in GLSL |
| 443 | class CbufNode final { | 446 | class CbufNode final { |
| 444 | public: | 447 | public: |
| 445 | explicit CbufNode(u32 index, Node offset) : index{index}, offset{offset} {} | 448 | explicit CbufNode(u32 index, Node offset) : index{index}, offset{std::move(offset)} {} |
| 446 | 449 | ||
| 447 | u32 GetIndex() const { | 450 | u32 GetIndex() const { |
| 448 | return index; | 451 | return index; |
| 449 | } | 452 | } |
| 450 | 453 | ||
| 451 | Node GetOffset() const { | 454 | const Node& GetOffset() const { |
| 452 | return offset; | 455 | return offset; |
| 453 | } | 456 | } |
| 454 | 457 | ||
| 455 | private: | 458 | private: |
| 456 | const u32 index; | 459 | u32 index{}; |
| 457 | const Node offset; | 460 | Node offset; |
| 458 | }; | 461 | }; |
| 459 | 462 | ||
| 460 | /// Local memory node | 463 | /// Local memory node |
| 461 | class LmemNode final { | 464 | class LmemNode final { |
| 462 | public: | 465 | public: |
| 463 | explicit LmemNode(Node address) : address{address} {} | 466 | explicit LmemNode(Node address) : address{std::move(address)} {} |
| 464 | 467 | ||
| 465 | Node GetAddress() const { | 468 | const Node& GetAddress() const { |
| 466 | return address; | 469 | return address; |
| 467 | } | 470 | } |
| 468 | 471 | ||
| 469 | private: | 472 | private: |
| 470 | const Node address; | 473 | Node address; |
| 471 | }; | 474 | }; |
| 472 | 475 | ||
| 473 | /// Global memory node | 476 | /// Global memory node |
| 474 | class GmemNode final { | 477 | class GmemNode final { |
| 475 | public: | 478 | public: |
| 476 | explicit GmemNode(Node real_address, Node base_address, const GlobalMemoryBase& descriptor) | 479 | explicit GmemNode(Node real_address, Node base_address, const GlobalMemoryBase& descriptor) |
| 477 | : real_address{real_address}, base_address{base_address}, descriptor{descriptor} {} | 480 | : real_address{std::move(real_address)}, base_address{std::move(base_address)}, |
| 481 | descriptor{descriptor} {} | ||
| 478 | 482 | ||
| 479 | Node GetRealAddress() const { | 483 | const Node& GetRealAddress() const { |
| 480 | return real_address; | 484 | return real_address; |
| 481 | } | 485 | } |
| 482 | 486 | ||
| 483 | Node GetBaseAddress() const { | 487 | const Node& GetBaseAddress() const { |
| 484 | return base_address; | 488 | return base_address; |
| 485 | } | 489 | } |
| 486 | 490 | ||
| @@ -489,9 +493,9 @@ public: | |||
| 489 | } | 493 | } |
| 490 | 494 | ||
| 491 | private: | 495 | private: |
| 492 | const Node real_address; | 496 | Node real_address; |
| 493 | const Node base_address; | 497 | Node base_address; |
| 494 | const GlobalMemoryBase descriptor; | 498 | GlobalMemoryBase descriptor; |
| 495 | }; | 499 | }; |
| 496 | 500 | ||
| 497 | /// Commentary, can be dropped | 501 | /// Commentary, can be dropped |