emit_glasm_not_implemented.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. // Copyright 2021 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <string_view>
  5. #include "shader_recompiler/backend/glasm/emit_context.h"
  6. #include "shader_recompiler/backend/glasm/emit_glasm_instructions.h"
  7. #include "shader_recompiler/frontend/ir/program.h"
  8. #include "shader_recompiler/frontend/ir/value.h"
  9. #ifdef _MSC_VER
  10. #pragma warning(disable : 4100)
  11. #endif
  12. namespace Shader::Backend::GLASM {
  13. #define NotImplemented() throw NotImplementedException("GLASM instruction {}", __LINE__)
  14. static void DefinePhi(EmitContext& ctx, IR::Inst& phi) {
  15. switch (phi.Type()) {
  16. case IR::Type::U1:
  17. case IR::Type::U32:
  18. case IR::Type::F32:
  19. ctx.reg_alloc.Define(phi);
  20. break;
  21. case IR::Type::U64:
  22. case IR::Type::F64:
  23. ctx.reg_alloc.LongDefine(phi);
  24. break;
  25. default:
  26. throw NotImplementedException("Phi node type {}", phi.Type());
  27. }
  28. }
  29. void EmitPhi(EmitContext& ctx, IR::Inst& phi) {
  30. const size_t num_args{phi.NumArgs()};
  31. for (size_t i = 0; i < num_args; ++i) {
  32. ctx.reg_alloc.Consume(phi.Arg(i));
  33. }
  34. if (!phi.Definition<Id>().is_valid) {
  35. // The phi node wasn't forward defined
  36. DefinePhi(ctx, phi);
  37. }
  38. }
  39. void EmitVoid(EmitContext&) {}
  40. void EmitReference(EmitContext& ctx, const IR::Value& value) {
  41. ctx.reg_alloc.Consume(value);
  42. }
  43. void EmitPhiMove(EmitContext& ctx, const IR::Value& phi_value, const IR::Value& value) {
  44. IR::Inst& phi{RegAlloc::AliasInst(*phi_value.Inst())};
  45. if (!phi.Definition<Id>().is_valid) {
  46. // The phi node wasn't forward defined
  47. DefinePhi(ctx, phi);
  48. }
  49. const Register phi_reg{ctx.reg_alloc.Consume(IR::Value{&phi})};
  50. const Value eval_value{ctx.reg_alloc.Consume(value)};
  51. if (phi_reg == eval_value) {
  52. return;
  53. }
  54. switch (phi.Flags<IR::Type>()) {
  55. case IR::Type::U1:
  56. case IR::Type::U32:
  57. case IR::Type::F32:
  58. ctx.Add("MOV.S {}.x,{};", phi_reg, ScalarS32{eval_value});
  59. break;
  60. case IR::Type::U64:
  61. case IR::Type::F64:
  62. ctx.Add("MOV.U64 {}.x,{};", phi_reg, ScalarRegister{eval_value});
  63. break;
  64. default:
  65. throw NotImplementedException("Phi node type {}", phi.Type());
  66. }
  67. }
  68. void EmitJoin(EmitContext& ctx) {
  69. NotImplemented();
  70. }
  71. void EmitDemoteToHelperInvocation(EmitContext& ctx) {
  72. ctx.Add("KIL TR.x;");
  73. }
  74. void EmitBarrier(EmitContext& ctx) {
  75. ctx.Add("BAR;");
  76. }
  77. void EmitWorkgroupMemoryBarrier(EmitContext& ctx) {
  78. ctx.Add("MEMBAR.CTA;");
  79. }
  80. void EmitDeviceMemoryBarrier(EmitContext& ctx) {
  81. ctx.Add("MEMBAR;");
  82. }
  83. void EmitPrologue(EmitContext& ctx) {
  84. // TODO
  85. }
  86. void EmitEpilogue(EmitContext& ctx) {
  87. // TODO
  88. }
  89. void EmitEmitVertex(EmitContext& ctx, ScalarS32 stream) {
  90. if (stream.type == Type::U32 && stream.imm_u32 == 0) {
  91. ctx.Add("EMIT;");
  92. } else {
  93. ctx.Add("EMITS {};", stream);
  94. }
  95. }
  96. void EmitEndPrimitive(EmitContext& ctx, const IR::Value& stream) {
  97. if (!stream.IsImmediate()) {
  98. LOG_WARNING(Shader_GLASM, "Stream is not immediate");
  99. }
  100. ctx.reg_alloc.Consume(stream);
  101. ctx.Add("ENDPRIM;");
  102. }
  103. void EmitGetRegister(EmitContext& ctx) {
  104. NotImplemented();
  105. }
  106. void EmitSetRegister(EmitContext& ctx) {
  107. NotImplemented();
  108. }
  109. void EmitGetPred(EmitContext& ctx) {
  110. NotImplemented();
  111. }
  112. void EmitSetPred(EmitContext& ctx) {
  113. NotImplemented();
  114. }
  115. void EmitSetGotoVariable(EmitContext& ctx) {
  116. NotImplemented();
  117. }
  118. void EmitGetGotoVariable(EmitContext& ctx) {
  119. NotImplemented();
  120. }
  121. void EmitSetIndirectBranchVariable(EmitContext& ctx) {
  122. NotImplemented();
  123. }
  124. void EmitGetIndirectBranchVariable(EmitContext& ctx) {
  125. NotImplemented();
  126. }
  127. void EmitGetZFlag(EmitContext& ctx) {
  128. NotImplemented();
  129. }
  130. void EmitGetSFlag(EmitContext& ctx) {
  131. NotImplemented();
  132. }
  133. void EmitGetCFlag(EmitContext& ctx) {
  134. NotImplemented();
  135. }
  136. void EmitGetOFlag(EmitContext& ctx) {
  137. NotImplemented();
  138. }
  139. void EmitSetZFlag(EmitContext& ctx) {
  140. NotImplemented();
  141. }
  142. void EmitSetSFlag(EmitContext& ctx) {
  143. NotImplemented();
  144. }
  145. void EmitSetCFlag(EmitContext& ctx) {
  146. NotImplemented();
  147. }
  148. void EmitSetOFlag(EmitContext& ctx) {
  149. NotImplemented();
  150. }
  151. void EmitWorkgroupId(EmitContext& ctx, IR::Inst& inst) {
  152. ctx.Add("MOV.S {},invocation.groupid;", inst);
  153. }
  154. void EmitLocalInvocationId(EmitContext& ctx, IR::Inst& inst) {
  155. ctx.Add("MOV.S {},invocation.localid;", inst);
  156. }
  157. void EmitInvocationId(EmitContext& ctx, IR::Inst& inst) {
  158. ctx.Add("MOV.S {}.x,primitive_invocation.x;", inst);
  159. }
  160. void EmitSampleId(EmitContext& ctx, IR::Inst& inst) {
  161. ctx.Add("MOV.S {}.x,fragment.sampleid.x;", inst);
  162. }
  163. void EmitIsHelperInvocation(EmitContext& ctx, IR::Inst& inst) {
  164. ctx.Add("MOV.S {}.x,fragment.helperthread.x;", inst);
  165. }
  166. void EmitYDirection(EmitContext& ctx, IR::Inst& inst) {
  167. ctx.uses_y_direction = true;
  168. ctx.Add("MOV.F {}.x,y_direction[0].w;", inst);
  169. }
  170. void EmitResolutionDownFactor(EmitContext& ctx, IR::Inst& inst) {
  171. ctx.Add("MOV.F {}.x,scaling[0].z;", inst);
  172. }
  173. void EmitUndefU1(EmitContext& ctx, IR::Inst& inst) {
  174. ctx.Add("MOV.S {}.x,0;", inst);
  175. }
  176. void EmitUndefU8(EmitContext& ctx, IR::Inst& inst) {
  177. ctx.Add("MOV.S {}.x,0;", inst);
  178. }
  179. void EmitUndefU16(EmitContext& ctx, IR::Inst& inst) {
  180. ctx.Add("MOV.S {}.x,0;", inst);
  181. }
  182. void EmitUndefU32(EmitContext& ctx, IR::Inst& inst) {
  183. ctx.Add("MOV.S {}.x,0;", inst);
  184. }
  185. void EmitUndefU64(EmitContext& ctx, IR::Inst& inst) {
  186. ctx.LongAdd("MOV.S64 {}.x,0;", inst);
  187. }
  188. void EmitGetZeroFromOp(EmitContext& ctx) {
  189. NotImplemented();
  190. }
  191. void EmitGetSignFromOp(EmitContext& ctx) {
  192. NotImplemented();
  193. }
  194. void EmitGetCarryFromOp(EmitContext& ctx) {
  195. NotImplemented();
  196. }
  197. void EmitGetOverflowFromOp(EmitContext& ctx) {
  198. NotImplemented();
  199. }
  200. void EmitGetSparseFromOp(EmitContext& ctx) {
  201. NotImplemented();
  202. }
  203. void EmitGetInBoundsFromOp(EmitContext& ctx) {
  204. NotImplemented();
  205. }
  206. void EmitLogicalOr(EmitContext& ctx, IR::Inst& inst, ScalarS32 a, ScalarS32 b) {
  207. ctx.Add("OR.S {},{},{};", inst, a, b);
  208. }
  209. void EmitLogicalAnd(EmitContext& ctx, IR::Inst& inst, ScalarS32 a, ScalarS32 b) {
  210. ctx.Add("AND.S {},{},{};", inst, a, b);
  211. }
  212. void EmitLogicalXor(EmitContext& ctx, IR::Inst& inst, ScalarS32 a, ScalarS32 b) {
  213. ctx.Add("XOR.S {},{},{};", inst, a, b);
  214. }
  215. void EmitLogicalNot(EmitContext& ctx, IR::Inst& inst, ScalarS32 value) {
  216. ctx.Add("SEQ.S {},{},0;", inst, value);
  217. }
  218. } // namespace Shader::Backend::GLASM