node.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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. Branch, /// (uint branch_target) -> void
  147. BranchIndirect, /// (uint branch_target) -> void
  148. PushFlowStack, /// (uint branch_target) -> void
  149. PopFlowStack, /// () -> void
  150. Exit, /// () -> void
  151. Discard, /// () -> void
  152. EmitVertex, /// () -> void
  153. EndPrimitive, /// () -> void
  154. InvocationId, /// () -> int
  155. YNegate, /// () -> float
  156. LocalInvocationIdX, /// () -> uint
  157. LocalInvocationIdY, /// () -> uint
  158. LocalInvocationIdZ, /// () -> uint
  159. WorkGroupIdX, /// () -> uint
  160. WorkGroupIdY, /// () -> uint
  161. WorkGroupIdZ, /// () -> uint
  162. BallotThread, /// (bool) -> uint
  163. VoteAll, /// (bool) -> bool
  164. VoteAny, /// (bool) -> bool
  165. VoteEqual, /// (bool) -> bool
  166. ThreadId, /// () -> uint
  167. ShuffleIndexed, /// (uint value, uint index) -> uint
  168. MemoryBarrierGL, /// () -> void
  169. Amount,
  170. };
  171. enum class InternalFlag {
  172. Zero = 0,
  173. Sign = 1,
  174. Carry = 2,
  175. Overflow = 3,
  176. Amount = 4,
  177. };
  178. enum class MetaStackClass {
  179. Ssy,
  180. Pbk,
  181. };
  182. class OperationNode;
  183. class ConditionalNode;
  184. class GprNode;
  185. class ImmediateNode;
  186. class InternalFlagNode;
  187. class PredicateNode;
  188. class AbufNode;
  189. class CbufNode;
  190. class LmemNode;
  191. class PatchNode;
  192. class SmemNode;
  193. class GmemNode;
  194. class CommentNode;
  195. using NodeData = std::variant<OperationNode, ConditionalNode, GprNode, ImmediateNode,
  196. InternalFlagNode, PredicateNode, AbufNode, PatchNode, CbufNode,
  197. LmemNode, SmemNode, GmemNode, CommentNode>;
  198. using Node = std::shared_ptr<NodeData>;
  199. using Node4 = std::array<Node, 4>;
  200. using NodeBlock = std::vector<Node>;
  201. class Sampler {
  202. public:
  203. /// This constructor is for bound samplers
  204. constexpr explicit Sampler(u32 index, u32 offset, Tegra::Shader::TextureType type,
  205. bool is_array, bool is_shadow, bool is_buffer)
  206. : index{index}, offset{offset}, type{type}, is_array{is_array}, is_shadow{is_shadow},
  207. is_buffer{is_buffer} {}
  208. /// This constructor is for bindless samplers
  209. constexpr explicit Sampler(u32 index, u32 offset, u32 buffer, Tegra::Shader::TextureType type,
  210. bool is_array, bool is_shadow, bool is_buffer)
  211. : index{index}, offset{offset}, buffer{buffer}, type{type}, is_array{is_array},
  212. is_shadow{is_shadow}, is_buffer{is_buffer}, is_bindless{true} {}
  213. constexpr u32 GetIndex() const {
  214. return index;
  215. }
  216. constexpr u32 GetOffset() const {
  217. return offset;
  218. }
  219. constexpr u32 GetBuffer() const {
  220. return buffer;
  221. }
  222. constexpr Tegra::Shader::TextureType GetType() const {
  223. return type;
  224. }
  225. constexpr bool IsArray() const {
  226. return is_array;
  227. }
  228. constexpr bool IsShadow() const {
  229. return is_shadow;
  230. }
  231. constexpr bool IsBuffer() const {
  232. return is_buffer;
  233. }
  234. constexpr bool IsBindless() const {
  235. return is_bindless;
  236. }
  237. private:
  238. u32 index{}; ///< Emulated index given for the this sampler.
  239. u32 offset{}; ///< Offset in the const buffer from where the sampler is being read.
  240. u32 buffer{}; ///< Buffer where the bindless sampler is being read (unused on bound samplers).
  241. Tegra::Shader::TextureType type{}; ///< The type used to sample this texture (Texture2D, etc)
  242. bool is_array{}; ///< Whether the texture is being sampled as an array texture or not.
  243. bool is_shadow{}; ///< Whether the texture is being sampled as a depth texture or not.
  244. bool is_buffer{}; ///< Whether the texture is a texture buffer without sampler.
  245. bool is_bindless{}; ///< Whether this sampler belongs to a bindless texture or not.
  246. };
  247. class Image final {
  248. public:
  249. /// This constructor is for bound images
  250. constexpr explicit Image(u32 index, u32 offset, Tegra::Shader::ImageType type)
  251. : index{index}, offset{offset}, type{type} {}
  252. /// This constructor is for bindless samplers
  253. constexpr explicit Image(u32 index, u32 offset, u32 buffer, Tegra::Shader::ImageType type)
  254. : index{index}, offset{offset}, buffer{buffer}, type{type}, is_bindless{true} {}
  255. void MarkWrite() {
  256. is_written = true;
  257. }
  258. void MarkRead() {
  259. is_read = true;
  260. }
  261. void MarkAtomic() {
  262. MarkWrite();
  263. MarkRead();
  264. is_atomic = true;
  265. }
  266. constexpr u32 GetIndex() const {
  267. return index;
  268. }
  269. constexpr u32 GetOffset() const {
  270. return offset;
  271. }
  272. constexpr u32 GetBuffer() const {
  273. return buffer;
  274. }
  275. constexpr Tegra::Shader::ImageType GetType() const {
  276. return type;
  277. }
  278. constexpr bool IsBindless() const {
  279. return is_bindless;
  280. }
  281. constexpr bool IsWritten() const {
  282. return is_written;
  283. }
  284. constexpr bool IsRead() const {
  285. return is_read;
  286. }
  287. constexpr bool IsAtomic() const {
  288. return is_atomic;
  289. }
  290. private:
  291. u32 index{};
  292. u32 offset{};
  293. u32 buffer{};
  294. Tegra::Shader::ImageType type{};
  295. bool is_bindless{};
  296. bool is_written{};
  297. bool is_read{};
  298. bool is_atomic{};
  299. };
  300. struct GlobalMemoryBase {
  301. u32 cbuf_index{};
  302. u32 cbuf_offset{};
  303. bool operator<(const GlobalMemoryBase& rhs) const {
  304. return std::tie(cbuf_index, cbuf_offset) < std::tie(rhs.cbuf_index, rhs.cbuf_offset);
  305. }
  306. };
  307. /// Parameters describing an arithmetic operation
  308. struct MetaArithmetic {
  309. bool precise{}; ///< Whether the operation can be constraint or not
  310. };
  311. /// Parameters describing a texture sampler
  312. struct MetaTexture {
  313. const Sampler& sampler;
  314. Node array;
  315. Node depth_compare;
  316. std::vector<Node> aoffi;
  317. std::vector<Node> ptp;
  318. std::vector<Node> derivates;
  319. Node bias;
  320. Node lod;
  321. Node component{};
  322. u32 element{};
  323. };
  324. struct MetaImage {
  325. const Image& image;
  326. std::vector<Node> values;
  327. u32 element{};
  328. };
  329. /// Parameters that modify an operation but are not part of any particular operand
  330. using Meta =
  331. std::variant<MetaArithmetic, MetaTexture, MetaImage, MetaStackClass, Tegra::Shader::HalfType>;
  332. class AmendNode {
  333. public:
  334. std::optional<u32> GetAmendIndex() const {
  335. if (amend_index == amend_null_index) {
  336. return std::nullopt;
  337. }
  338. return {amend_index};
  339. }
  340. void SetAmendIndex(u32 index) {
  341. amend_index = index;
  342. }
  343. void ClearAmend() {
  344. amend_index = amend_null_index;
  345. }
  346. private:
  347. static constexpr u32 amend_null_index = 0xFFFFFFFF;
  348. u32 amend_index{amend_null_index};
  349. };
  350. /// Holds any kind of operation that can be done in the IR
  351. class OperationNode final : public AmendNode {
  352. public:
  353. explicit OperationNode(OperationCode code) : OperationNode(code, Meta{}) {}
  354. explicit OperationNode(OperationCode code, Meta meta)
  355. : OperationNode(code, std::move(meta), std::vector<Node>{}) {}
  356. explicit OperationNode(OperationCode code, std::vector<Node> operands)
  357. : OperationNode(code, Meta{}, std::move(operands)) {}
  358. explicit OperationNode(OperationCode code, Meta meta, std::vector<Node> operands)
  359. : code{code}, meta{std::move(meta)}, operands{std::move(operands)} {}
  360. template <typename... Args>
  361. explicit OperationNode(OperationCode code, Meta meta, Args&&... operands)
  362. : code{code}, meta{std::move(meta)}, operands{operands...} {}
  363. OperationCode GetCode() const {
  364. return code;
  365. }
  366. const Meta& GetMeta() const {
  367. return meta;
  368. }
  369. std::size_t GetOperandsCount() const {
  370. return operands.size();
  371. }
  372. const Node& operator[](std::size_t operand_index) const {
  373. return operands.at(operand_index);
  374. }
  375. private:
  376. OperationCode code{};
  377. Meta meta{};
  378. std::vector<Node> operands;
  379. };
  380. /// Encloses inside any kind of node that returns a boolean conditionally-executed code
  381. class ConditionalNode final : public AmendNode {
  382. public:
  383. explicit ConditionalNode(Node condition, std::vector<Node>&& code)
  384. : condition{std::move(condition)}, code{std::move(code)} {}
  385. const Node& GetCondition() const {
  386. return condition;
  387. }
  388. const std::vector<Node>& GetCode() const {
  389. return code;
  390. }
  391. private:
  392. Node condition; ///< Condition to be satisfied
  393. std::vector<Node> code; ///< Code to execute
  394. };
  395. /// A general purpose register
  396. class GprNode final {
  397. public:
  398. explicit constexpr GprNode(Tegra::Shader::Register index) : index{index} {}
  399. u32 GetIndex() const {
  400. return static_cast<u32>(index);
  401. }
  402. private:
  403. Tegra::Shader::Register index{};
  404. };
  405. /// A 32-bits value that represents an immediate value
  406. class ImmediateNode final {
  407. public:
  408. explicit constexpr ImmediateNode(u32 value) : value{value} {}
  409. u32 GetValue() const {
  410. return value;
  411. }
  412. private:
  413. u32 value{};
  414. };
  415. /// One of Maxwell's internal flags
  416. class InternalFlagNode final {
  417. public:
  418. explicit constexpr InternalFlagNode(InternalFlag flag) : flag{flag} {}
  419. InternalFlag GetFlag() const {
  420. return flag;
  421. }
  422. private:
  423. InternalFlag flag{};
  424. };
  425. /// A predicate register, it can be negated without additional nodes
  426. class PredicateNode final {
  427. public:
  428. explicit constexpr PredicateNode(Tegra::Shader::Pred index, bool negated)
  429. : index{index}, negated{negated} {}
  430. Tegra::Shader::Pred GetIndex() const {
  431. return index;
  432. }
  433. bool IsNegated() const {
  434. return negated;
  435. }
  436. private:
  437. Tegra::Shader::Pred index{};
  438. bool negated{};
  439. };
  440. /// Attribute buffer memory (known as attributes or varyings in GLSL terms)
  441. class AbufNode final {
  442. public:
  443. // Initialize for standard attributes (index is explicit).
  444. explicit AbufNode(Tegra::Shader::Attribute::Index index, u32 element, Node buffer = {})
  445. : buffer{std::move(buffer)}, index{index}, element{element} {}
  446. // Initialize for physical attributes (index is a variable value).
  447. explicit AbufNode(Node physical_address, Node buffer = {})
  448. : physical_address{std::move(physical_address)}, buffer{std::move(buffer)} {}
  449. Tegra::Shader::Attribute::Index GetIndex() const {
  450. return index;
  451. }
  452. u32 GetElement() const {
  453. return element;
  454. }
  455. const Node& GetBuffer() const {
  456. return buffer;
  457. }
  458. bool IsPhysicalBuffer() const {
  459. return static_cast<bool>(physical_address);
  460. }
  461. const Node& GetPhysicalAddress() const {
  462. return physical_address;
  463. }
  464. private:
  465. Node physical_address;
  466. Node buffer;
  467. Tegra::Shader::Attribute::Index index{};
  468. u32 element{};
  469. };
  470. /// Patch memory (used to communicate tessellation stages).
  471. class PatchNode final {
  472. public:
  473. explicit PatchNode(u32 offset) : offset{offset} {}
  474. u32 GetOffset() const {
  475. return offset;
  476. }
  477. private:
  478. u32 offset{};
  479. };
  480. /// Constant buffer node, usually mapped to uniform buffers in GLSL
  481. class CbufNode final {
  482. public:
  483. explicit CbufNode(u32 index, Node offset) : index{index}, offset{std::move(offset)} {}
  484. u32 GetIndex() const {
  485. return index;
  486. }
  487. const Node& GetOffset() const {
  488. return offset;
  489. }
  490. private:
  491. u32 index{};
  492. Node offset;
  493. };
  494. /// Local memory node
  495. class LmemNode final {
  496. public:
  497. explicit LmemNode(Node address) : address{std::move(address)} {}
  498. const Node& GetAddress() const {
  499. return address;
  500. }
  501. private:
  502. Node address;
  503. };
  504. /// Shared memory node
  505. class SmemNode final {
  506. public:
  507. explicit SmemNode(Node address) : address{std::move(address)} {}
  508. const Node& GetAddress() const {
  509. return address;
  510. }
  511. private:
  512. Node address;
  513. };
  514. /// Global memory node
  515. class GmemNode final {
  516. public:
  517. explicit GmemNode(Node real_address, Node base_address, const GlobalMemoryBase& descriptor)
  518. : real_address{std::move(real_address)}, base_address{std::move(base_address)},
  519. descriptor{descriptor} {}
  520. const Node& GetRealAddress() const {
  521. return real_address;
  522. }
  523. const Node& GetBaseAddress() const {
  524. return base_address;
  525. }
  526. const GlobalMemoryBase& GetDescriptor() const {
  527. return descriptor;
  528. }
  529. private:
  530. Node real_address;
  531. Node base_address;
  532. GlobalMemoryBase descriptor;
  533. };
  534. /// Commentary, can be dropped
  535. class CommentNode final : public AmendNode {
  536. public:
  537. explicit CommentNode(std::string text) : text{std::move(text)} {}
  538. const std::string& GetText() const {
  539. return text;
  540. }
  541. private:
  542. std::string text;
  543. };
  544. } // namespace VideoCommon::Shader