node.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. // Copyright 2019 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <cstddef>
  7. #include <memory>
  8. #include <optional>
  9. #include <string>
  10. #include <tuple>
  11. #include <utility>
  12. #include <variant>
  13. #include <vector>
  14. #include "common/common_types.h"
  15. #include "video_core/engines/shader_bytecode.h"
  16. namespace VideoCommon::Shader {
  17. enum class OperationCode {
  18. Assign, /// (float& dest, float src) -> void
  19. Select, /// (MetaArithmetic, bool pred, float a, float b) -> float
  20. FAdd, /// (MetaArithmetic, float a, float b) -> float
  21. FMul, /// (MetaArithmetic, float a, float b) -> float
  22. FDiv, /// (MetaArithmetic, float a, float b) -> float
  23. FFma, /// (MetaArithmetic, float a, float b, float c) -> float
  24. FNegate, /// (MetaArithmetic, float a) -> float
  25. FAbsolute, /// (MetaArithmetic, float a) -> float
  26. FClamp, /// (MetaArithmetic, float value, float min, float max) -> float
  27. FCastHalf0, /// (MetaArithmetic, f16vec2 a) -> float
  28. FCastHalf1, /// (MetaArithmetic, f16vec2 a) -> float
  29. FMin, /// (MetaArithmetic, float a, float b) -> float
  30. FMax, /// (MetaArithmetic, float a, float b) -> float
  31. FCos, /// (MetaArithmetic, float a) -> float
  32. FSin, /// (MetaArithmetic, float a) -> float
  33. FExp2, /// (MetaArithmetic, float a) -> float
  34. FLog2, /// (MetaArithmetic, float a) -> float
  35. FInverseSqrt, /// (MetaArithmetic, float a) -> float
  36. FSqrt, /// (MetaArithmetic, float a) -> float
  37. FRoundEven, /// (MetaArithmetic, float a) -> float
  38. FFloor, /// (MetaArithmetic, float a) -> float
  39. FCeil, /// (MetaArithmetic, float a) -> float
  40. FTrunc, /// (MetaArithmetic, float a) -> float
  41. FCastInteger, /// (MetaArithmetic, int a) -> float
  42. FCastUInteger, /// (MetaArithmetic, uint a) -> float
  43. FSwizzleAdd, /// (float a, float b, uint mask) -> float
  44. IAdd, /// (MetaArithmetic, int a, int b) -> int
  45. IMul, /// (MetaArithmetic, int a, int b) -> int
  46. IDiv, /// (MetaArithmetic, int a, int b) -> int
  47. INegate, /// (MetaArithmetic, int a) -> int
  48. IAbsolute, /// (MetaArithmetic, int a) -> int
  49. IMin, /// (MetaArithmetic, int a, int b) -> int
  50. IMax, /// (MetaArithmetic, int a, int b) -> int
  51. ICastFloat, /// (MetaArithmetic, float a) -> int
  52. ICastUnsigned, /// (MetaArithmetic, uint a) -> int
  53. ILogicalShiftLeft, /// (MetaArithmetic, int a, uint b) -> int
  54. ILogicalShiftRight, /// (MetaArithmetic, int a, uint b) -> int
  55. IArithmeticShiftRight, /// (MetaArithmetic, int a, uint b) -> int
  56. IBitwiseAnd, /// (MetaArithmetic, int a, int b) -> int
  57. IBitwiseOr, /// (MetaArithmetic, int a, int b) -> int
  58. IBitwiseXor, /// (MetaArithmetic, int a, int b) -> int
  59. IBitwiseNot, /// (MetaArithmetic, int a) -> int
  60. IBitfieldInsert, /// (MetaArithmetic, int base, int insert, int offset, int bits) -> int
  61. IBitfieldExtract, /// (MetaArithmetic, int value, int offset, int offset) -> int
  62. IBitCount, /// (MetaArithmetic, int) -> int
  63. IBitMSB, /// (MetaArithmetic, int) -> int
  64. UAdd, /// (MetaArithmetic, uint a, uint b) -> uint
  65. UMul, /// (MetaArithmetic, uint a, uint b) -> uint
  66. UDiv, /// (MetaArithmetic, uint a, uint b) -> uint
  67. UMin, /// (MetaArithmetic, uint a, uint b) -> uint
  68. UMax, /// (MetaArithmetic, uint a, uint b) -> uint
  69. UCastFloat, /// (MetaArithmetic, float a) -> uint
  70. UCastSigned, /// (MetaArithmetic, int a) -> uint
  71. ULogicalShiftLeft, /// (MetaArithmetic, uint a, uint b) -> uint
  72. ULogicalShiftRight, /// (MetaArithmetic, uint a, uint b) -> uint
  73. UArithmeticShiftRight, /// (MetaArithmetic, uint a, uint b) -> uint
  74. UBitwiseAnd, /// (MetaArithmetic, uint a, uint b) -> uint
  75. UBitwiseOr, /// (MetaArithmetic, uint a, uint b) -> uint
  76. UBitwiseXor, /// (MetaArithmetic, uint a, uint b) -> uint
  77. UBitwiseNot, /// (MetaArithmetic, uint a) -> uint
  78. UBitfieldInsert, /// (MetaArithmetic, uint base, uint insert, int offset, int bits) -> uint
  79. UBitfieldExtract, /// (MetaArithmetic, uint value, int offset, int offset) -> uint
  80. UBitCount, /// (MetaArithmetic, uint) -> uint
  81. UBitMSB, /// (MetaArithmetic, uint) -> uint
  82. HAdd, /// (MetaArithmetic, f16vec2 a, f16vec2 b) -> f16vec2
  83. HMul, /// (MetaArithmetic, f16vec2 a, f16vec2 b) -> f16vec2
  84. HFma, /// (MetaArithmetic, f16vec2 a, f16vec2 b, f16vec2 c) -> f16vec2
  85. HAbsolute, /// (f16vec2 a) -> f16vec2
  86. HNegate, /// (f16vec2 a, bool first, bool second) -> f16vec2
  87. HClamp, /// (f16vec2 src, float min, float max) -> f16vec2
  88. HCastFloat, /// (MetaArithmetic, float a) -> f16vec2
  89. HUnpack, /// (Tegra::Shader::HalfType, T value) -> f16vec2
  90. HMergeF32, /// (f16vec2 src) -> float
  91. HMergeH0, /// (f16vec2 dest, f16vec2 src) -> f16vec2
  92. HMergeH1, /// (f16vec2 dest, f16vec2 src) -> f16vec2
  93. HPack2, /// (float a, float b) -> f16vec2
  94. LogicalAssign, /// (bool& dst, bool src) -> void
  95. LogicalAnd, /// (bool a, bool b) -> bool
  96. LogicalOr, /// (bool a, bool b) -> bool
  97. LogicalXor, /// (bool a, bool b) -> bool
  98. LogicalNegate, /// (bool a) -> bool
  99. LogicalPick2, /// (bool2 pair, uint index) -> bool
  100. LogicalAnd2, /// (bool2 a) -> bool
  101. LogicalFLessThan, /// (float a, float b) -> bool
  102. LogicalFEqual, /// (float a, float b) -> bool
  103. LogicalFLessEqual, /// (float a, float b) -> bool
  104. LogicalFGreaterThan, /// (float a, float b) -> bool
  105. LogicalFNotEqual, /// (float a, float b) -> bool
  106. LogicalFGreaterEqual, /// (float a, float b) -> bool
  107. LogicalFIsNan, /// (float a) -> bool
  108. LogicalILessThan, /// (int a, int b) -> bool
  109. LogicalIEqual, /// (int a, int b) -> bool
  110. LogicalILessEqual, /// (int a, int b) -> bool
  111. LogicalIGreaterThan, /// (int a, int b) -> bool
  112. LogicalINotEqual, /// (int a, int b) -> bool
  113. LogicalIGreaterEqual, /// (int a, int b) -> bool
  114. LogicalULessThan, /// (uint a, uint b) -> bool
  115. LogicalUEqual, /// (uint a, uint b) -> bool
  116. LogicalULessEqual, /// (uint a, uint b) -> bool
  117. LogicalUGreaterThan, /// (uint a, uint b) -> bool
  118. LogicalUNotEqual, /// (uint a, uint b) -> bool
  119. LogicalUGreaterEqual, /// (uint a, uint b) -> bool
  120. Logical2HLessThan, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
  121. Logical2HEqual, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
  122. Logical2HLessEqual, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
  123. Logical2HGreaterThan, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
  124. Logical2HNotEqual, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
  125. Logical2HGreaterEqual, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
  126. Logical2HLessThanWithNan, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
  127. Logical2HEqualWithNan, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
  128. Logical2HLessEqualWithNan, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
  129. Logical2HGreaterThanWithNan, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
  130. Logical2HNotEqualWithNan, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
  131. Logical2HGreaterEqualWithNan, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
  132. Texture, /// (MetaTexture, float[N] coords) -> float4
  133. TextureLod, /// (MetaTexture, float[N] coords) -> float4
  134. TextureGather, /// (MetaTexture, float[N] coords) -> float4
  135. TextureQueryDimensions, /// (MetaTexture, float a) -> float4
  136. TextureQueryLod, /// (MetaTexture, float[N] coords) -> float4
  137. TexelFetch, /// (MetaTexture, int[N], int) -> float4
  138. TextureGradient, /// (MetaTexture, float[N] coords, float[N*2] derivates) -> float4
  139. ImageLoad, /// (MetaImage, int[N] coords) -> void
  140. ImageStore, /// (MetaImage, int[N] coords) -> void
  141. AtomicImageAdd, /// (MetaImage, int[N] coords) -> void
  142. AtomicImageAnd, /// (MetaImage, int[N] coords) -> void
  143. AtomicImageOr, /// (MetaImage, int[N] coords) -> void
  144. AtomicImageXor, /// (MetaImage, int[N] coords) -> void
  145. AtomicImageExchange, /// (MetaImage, int[N] coords) -> void
  146. AtomicAdd, /// (memory, {u}int) -> {u}int
  147. Branch, /// (uint branch_target) -> void
  148. BranchIndirect, /// (uint branch_target) -> void
  149. PushFlowStack, /// (uint branch_target) -> void
  150. PopFlowStack, /// () -> void
  151. Exit, /// () -> void
  152. Discard, /// () -> void
  153. EmitVertex, /// () -> void
  154. EndPrimitive, /// () -> void
  155. InvocationId, /// () -> int
  156. YNegate, /// () -> float
  157. LocalInvocationIdX, /// () -> uint
  158. LocalInvocationIdY, /// () -> uint
  159. LocalInvocationIdZ, /// () -> uint
  160. WorkGroupIdX, /// () -> uint
  161. WorkGroupIdY, /// () -> uint
  162. WorkGroupIdZ, /// () -> uint
  163. BallotThread, /// (bool) -> uint
  164. VoteAll, /// (bool) -> bool
  165. VoteAny, /// (bool) -> bool
  166. VoteEqual, /// (bool) -> bool
  167. ThreadId, /// () -> uint
  168. ShuffleIndexed, /// (uint value, uint index) -> uint
  169. MemoryBarrierGL, /// () -> void
  170. Amount,
  171. };
  172. enum class InternalFlag {
  173. Zero = 0,
  174. Sign = 1,
  175. Carry = 2,
  176. Overflow = 3,
  177. Amount = 4,
  178. };
  179. enum class MetaStackClass {
  180. Ssy,
  181. Pbk,
  182. };
  183. class OperationNode;
  184. class ConditionalNode;
  185. class GprNode;
  186. class ImmediateNode;
  187. class InternalFlagNode;
  188. class PredicateNode;
  189. class AbufNode;
  190. class CbufNode;
  191. class LmemNode;
  192. class PatchNode;
  193. class SmemNode;
  194. class GmemNode;
  195. class CommentNode;
  196. using NodeData = std::variant<OperationNode, ConditionalNode, GprNode, ImmediateNode,
  197. InternalFlagNode, PredicateNode, AbufNode, PatchNode, CbufNode,
  198. LmemNode, SmemNode, GmemNode, CommentNode>;
  199. using Node = std::shared_ptr<NodeData>;
  200. using Node4 = std::array<Node, 4>;
  201. using NodeBlock = std::vector<Node>;
  202. class Sampler {
  203. public:
  204. /// This constructor is for bound samplers
  205. constexpr explicit Sampler(u32 index, u32 offset, Tegra::Shader::TextureType type,
  206. bool is_array, bool is_shadow, bool is_buffer)
  207. : index{index}, offset{offset}, type{type}, is_array{is_array}, is_shadow{is_shadow},
  208. is_buffer{is_buffer} {}
  209. /// This constructor is for bindless samplers
  210. constexpr explicit Sampler(u32 index, u32 offset, u32 buffer, Tegra::Shader::TextureType type,
  211. bool is_array, bool is_shadow, bool is_buffer)
  212. : index{index}, offset{offset}, buffer{buffer}, type{type}, is_array{is_array},
  213. is_shadow{is_shadow}, is_buffer{is_buffer}, is_bindless{true} {}
  214. constexpr u32 GetIndex() const {
  215. return index;
  216. }
  217. constexpr u32 GetOffset() const {
  218. return offset;
  219. }
  220. constexpr u32 GetBuffer() const {
  221. return buffer;
  222. }
  223. constexpr Tegra::Shader::TextureType GetType() const {
  224. return type;
  225. }
  226. constexpr bool IsArray() const {
  227. return is_array;
  228. }
  229. constexpr bool IsShadow() const {
  230. return is_shadow;
  231. }
  232. constexpr bool IsBuffer() const {
  233. return is_buffer;
  234. }
  235. constexpr bool IsBindless() const {
  236. return is_bindless;
  237. }
  238. private:
  239. u32 index{}; ///< Emulated index given for the this sampler.
  240. u32 offset{}; ///< Offset in the const buffer from where the sampler is being read.
  241. u32 buffer{}; ///< Buffer where the bindless sampler is being read (unused on bound samplers).
  242. Tegra::Shader::TextureType type{}; ///< The type used to sample this texture (Texture2D, etc)
  243. bool is_array{}; ///< Whether the texture is being sampled as an array texture or not.
  244. bool is_shadow{}; ///< Whether the texture is being sampled as a depth texture or not.
  245. bool is_buffer{}; ///< Whether the texture is a texture buffer without sampler.
  246. bool is_bindless{}; ///< Whether this sampler belongs to a bindless texture or not.
  247. };
  248. class Image final {
  249. public:
  250. /// This constructor is for bound images
  251. constexpr explicit Image(u32 index, u32 offset, Tegra::Shader::ImageType type)
  252. : index{index}, offset{offset}, type{type} {}
  253. /// This constructor is for bindless samplers
  254. constexpr explicit Image(u32 index, u32 offset, u32 buffer, Tegra::Shader::ImageType type)
  255. : index{index}, offset{offset}, buffer{buffer}, type{type}, is_bindless{true} {}
  256. void MarkWrite() {
  257. is_written = true;
  258. }
  259. void MarkRead() {
  260. is_read = true;
  261. }
  262. void MarkAtomic() {
  263. MarkWrite();
  264. MarkRead();
  265. is_atomic = true;
  266. }
  267. constexpr u32 GetIndex() const {
  268. return index;
  269. }
  270. constexpr u32 GetOffset() const {
  271. return offset;
  272. }
  273. constexpr u32 GetBuffer() const {
  274. return buffer;
  275. }
  276. constexpr Tegra::Shader::ImageType GetType() const {
  277. return type;
  278. }
  279. constexpr bool IsBindless() const {
  280. return is_bindless;
  281. }
  282. constexpr bool IsWritten() const {
  283. return is_written;
  284. }
  285. constexpr bool IsRead() const {
  286. return is_read;
  287. }
  288. constexpr bool IsAtomic() const {
  289. return is_atomic;
  290. }
  291. private:
  292. u32 index{};
  293. u32 offset{};
  294. u32 buffer{};
  295. Tegra::Shader::ImageType type{};
  296. bool is_bindless{};
  297. bool is_written{};
  298. bool is_read{};
  299. bool is_atomic{};
  300. };
  301. struct GlobalMemoryBase {
  302. u32 cbuf_index{};
  303. u32 cbuf_offset{};
  304. bool operator<(const GlobalMemoryBase& rhs) const {
  305. return std::tie(cbuf_index, cbuf_offset) < std::tie(rhs.cbuf_index, rhs.cbuf_offset);
  306. }
  307. };
  308. /// Parameters describing an arithmetic operation
  309. struct MetaArithmetic {
  310. bool precise{}; ///< Whether the operation can be constraint or not
  311. };
  312. /// Parameters describing a texture sampler
  313. struct MetaTexture {
  314. const Sampler& sampler;
  315. Node array;
  316. Node depth_compare;
  317. std::vector<Node> aoffi;
  318. std::vector<Node> ptp;
  319. std::vector<Node> derivates;
  320. Node bias;
  321. Node lod;
  322. Node component{};
  323. u32 element{};
  324. };
  325. struct MetaImage {
  326. const Image& image;
  327. std::vector<Node> values;
  328. u32 element{};
  329. };
  330. /// Parameters that modify an operation but are not part of any particular operand
  331. using Meta =
  332. std::variant<MetaArithmetic, MetaTexture, MetaImage, MetaStackClass, Tegra::Shader::HalfType>;
  333. class AmendNode {
  334. public:
  335. std::optional<std::size_t> GetAmendIndex() const {
  336. if (amend_index == amend_null_index) {
  337. return std::nullopt;
  338. }
  339. return {amend_index};
  340. }
  341. void SetAmendIndex(std::size_t index) {
  342. amend_index = index;
  343. }
  344. void ClearAmend() {
  345. amend_index = amend_null_index;
  346. }
  347. private:
  348. static constexpr std::size_t amend_null_index = 0xFFFFFFFFFFFFFFFFULL;
  349. std::size_t amend_index{amend_null_index};
  350. };
  351. /// Holds any kind of operation that can be done in the IR
  352. class OperationNode final : public AmendNode {
  353. public:
  354. explicit OperationNode(OperationCode code) : OperationNode(code, Meta{}) {}
  355. explicit OperationNode(OperationCode code, Meta meta)
  356. : OperationNode(code, std::move(meta), std::vector<Node>{}) {}
  357. explicit OperationNode(OperationCode code, std::vector<Node> operands)
  358. : OperationNode(code, Meta{}, std::move(operands)) {}
  359. explicit OperationNode(OperationCode code, Meta meta, std::vector<Node> operands)
  360. : code{code}, meta{std::move(meta)}, operands{std::move(operands)} {}
  361. template <typename... Args>
  362. explicit OperationNode(OperationCode code, Meta meta, Args&&... operands)
  363. : code{code}, meta{std::move(meta)}, operands{operands...} {}
  364. OperationCode GetCode() const {
  365. return code;
  366. }
  367. const Meta& GetMeta() const {
  368. return meta;
  369. }
  370. std::size_t GetOperandsCount() const {
  371. return operands.size();
  372. }
  373. const Node& operator[](std::size_t operand_index) const {
  374. return operands.at(operand_index);
  375. }
  376. private:
  377. OperationCode code{};
  378. Meta meta{};
  379. std::vector<Node> operands;
  380. };
  381. /// Encloses inside any kind of node that returns a boolean conditionally-executed code
  382. class ConditionalNode final : public AmendNode {
  383. public:
  384. explicit ConditionalNode(Node condition, std::vector<Node>&& code)
  385. : condition{std::move(condition)}, code{std::move(code)} {}
  386. const Node& GetCondition() const {
  387. return condition;
  388. }
  389. const std::vector<Node>& GetCode() const {
  390. return code;
  391. }
  392. private:
  393. Node condition; ///< Condition to be satisfied
  394. std::vector<Node> code; ///< Code to execute
  395. };
  396. /// A general purpose register
  397. class GprNode final {
  398. public:
  399. explicit constexpr GprNode(Tegra::Shader::Register index) : index{index} {}
  400. u32 GetIndex() const {
  401. return static_cast<u32>(index);
  402. }
  403. private:
  404. Tegra::Shader::Register index{};
  405. };
  406. /// A 32-bits value that represents an immediate value
  407. class ImmediateNode final {
  408. public:
  409. explicit constexpr ImmediateNode(u32 value) : value{value} {}
  410. u32 GetValue() const {
  411. return value;
  412. }
  413. private:
  414. u32 value{};
  415. };
  416. /// One of Maxwell's internal flags
  417. class InternalFlagNode final {
  418. public:
  419. explicit constexpr InternalFlagNode(InternalFlag flag) : flag{flag} {}
  420. InternalFlag GetFlag() const {
  421. return flag;
  422. }
  423. private:
  424. InternalFlag flag{};
  425. };
  426. /// A predicate register, it can be negated without additional nodes
  427. class PredicateNode final {
  428. public:
  429. explicit constexpr PredicateNode(Tegra::Shader::Pred index, bool negated)
  430. : index{index}, negated{negated} {}
  431. Tegra::Shader::Pred GetIndex() const {
  432. return index;
  433. }
  434. bool IsNegated() const {
  435. return negated;
  436. }
  437. private:
  438. Tegra::Shader::Pred index{};
  439. bool negated{};
  440. };
  441. /// Attribute buffer memory (known as attributes or varyings in GLSL terms)
  442. class AbufNode final {
  443. public:
  444. // Initialize for standard attributes (index is explicit).
  445. explicit AbufNode(Tegra::Shader::Attribute::Index index, u32 element, Node buffer = {})
  446. : buffer{std::move(buffer)}, index{index}, element{element} {}
  447. // Initialize for physical attributes (index is a variable value).
  448. explicit AbufNode(Node physical_address, Node buffer = {})
  449. : physical_address{std::move(physical_address)}, buffer{std::move(buffer)} {}
  450. Tegra::Shader::Attribute::Index GetIndex() const {
  451. return index;
  452. }
  453. u32 GetElement() const {
  454. return element;
  455. }
  456. const Node& GetBuffer() const {
  457. return buffer;
  458. }
  459. bool IsPhysicalBuffer() const {
  460. return static_cast<bool>(physical_address);
  461. }
  462. const Node& GetPhysicalAddress() const {
  463. return physical_address;
  464. }
  465. private:
  466. Node physical_address;
  467. Node buffer;
  468. Tegra::Shader::Attribute::Index index{};
  469. u32 element{};
  470. };
  471. /// Patch memory (used to communicate tessellation stages).
  472. class PatchNode final {
  473. public:
  474. explicit PatchNode(u32 offset) : offset{offset} {}
  475. u32 GetOffset() const {
  476. return offset;
  477. }
  478. private:
  479. u32 offset{};
  480. };
  481. /// Constant buffer node, usually mapped to uniform buffers in GLSL
  482. class CbufNode final {
  483. public:
  484. explicit CbufNode(u32 index, Node offset) : index{index}, offset{std::move(offset)} {}
  485. u32 GetIndex() const {
  486. return index;
  487. }
  488. const Node& GetOffset() const {
  489. return offset;
  490. }
  491. private:
  492. u32 index{};
  493. Node offset;
  494. };
  495. /// Local memory node
  496. class LmemNode final {
  497. public:
  498. explicit LmemNode(Node address) : address{std::move(address)} {}
  499. const Node& GetAddress() const {
  500. return address;
  501. }
  502. private:
  503. Node address;
  504. };
  505. /// Shared memory node
  506. class SmemNode final {
  507. public:
  508. explicit SmemNode(Node address) : address{std::move(address)} {}
  509. const Node& GetAddress() const {
  510. return address;
  511. }
  512. private:
  513. Node address;
  514. };
  515. /// Global memory node
  516. class GmemNode final {
  517. public:
  518. explicit GmemNode(Node real_address, Node base_address, const GlobalMemoryBase& descriptor)
  519. : real_address{std::move(real_address)}, base_address{std::move(base_address)},
  520. descriptor{descriptor} {}
  521. const Node& GetRealAddress() const {
  522. return real_address;
  523. }
  524. const Node& GetBaseAddress() const {
  525. return base_address;
  526. }
  527. const GlobalMemoryBase& GetDescriptor() const {
  528. return descriptor;
  529. }
  530. private:
  531. Node real_address;
  532. Node base_address;
  533. GlobalMemoryBase descriptor;
  534. };
  535. /// Commentary, can be dropped
  536. class CommentNode final {
  537. public:
  538. explicit CommentNode(std::string text) : text{std::move(text)} {}
  539. const std::string& GetText() const {
  540. return text;
  541. }
  542. private:
  543. std::string text;
  544. };
  545. } // namespace VideoCommon::Shader