emit_glsl_composite.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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/glsl/emit_context.h"
  6. #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
  7. #include "shader_recompiler/frontend/ir/value.h"
  8. #include "shader_recompiler/profile.h"
  9. namespace Shader::Backend::GLSL {
  10. static constexpr std::string_view SWIZZLE{"xyzw"};
  11. void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
  12. std::string_view e2) {
  13. ctx.AddU32x2("{}=uvec2({},{});", inst, e1, e2);
  14. }
  15. void EmitCompositeConstructU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
  16. std::string_view e2, std::string_view e3) {
  17. ctx.AddU32x3("{}=uvec3({},{},{});", inst, e1, e2, e3);
  18. }
  19. void EmitCompositeConstructU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
  20. std::string_view e2, std::string_view e3, std::string_view e4) {
  21. ctx.AddU32x4("{}=uvec4({},{},{},{});", inst, e1, e2, e3, e4);
  22. }
  23. void EmitCompositeExtractU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
  24. u32 index) {
  25. ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
  26. }
  27. void EmitCompositeExtractU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
  28. u32 index) {
  29. ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
  30. }
  31. void EmitCompositeExtractU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
  32. u32 index) {
  33. ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
  34. }
  35. void EmitCompositeInsertU32x2(EmitContext& ctx, std::string_view composite, std::string_view object,
  36. u32 index) {
  37. ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
  38. }
  39. void EmitCompositeInsertU32x3(EmitContext& ctx, std::string_view composite, std::string_view object,
  40. u32 index) {
  41. ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
  42. }
  43. void EmitCompositeInsertU32x4(EmitContext& ctx, std::string_view composite, std::string_view object,
  44. u32 index) {
  45. ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
  46. }
  47. void EmitCompositeConstructF16x2([[maybe_unused]] EmitContext& ctx,
  48. [[maybe_unused]] std::string_view e1,
  49. [[maybe_unused]] std::string_view e2) {
  50. throw NotImplementedException("GLSL Instruction");
  51. }
  52. void EmitCompositeConstructF16x3([[maybe_unused]] EmitContext& ctx,
  53. [[maybe_unused]] std::string_view e1,
  54. [[maybe_unused]] std::string_view e2,
  55. [[maybe_unused]] std::string_view e3) {
  56. throw NotImplementedException("GLSL Instruction");
  57. }
  58. void EmitCompositeConstructF16x4([[maybe_unused]] EmitContext& ctx,
  59. [[maybe_unused]] std::string_view e1,
  60. [[maybe_unused]] std::string_view e2,
  61. [[maybe_unused]] std::string_view e3,
  62. [[maybe_unused]] std::string_view e4) {
  63. throw NotImplementedException("GLSL Instruction");
  64. }
  65. void EmitCompositeExtractF16x2([[maybe_unused]] EmitContext& ctx,
  66. [[maybe_unused]] std::string_view composite,
  67. [[maybe_unused]] u32 index) {
  68. throw NotImplementedException("GLSL Instruction");
  69. }
  70. void EmitCompositeExtractF16x3([[maybe_unused]] EmitContext& ctx,
  71. [[maybe_unused]] std::string_view composite,
  72. [[maybe_unused]] u32 index) {
  73. throw NotImplementedException("GLSL Instruction");
  74. }
  75. void EmitCompositeExtractF16x4([[maybe_unused]] EmitContext& ctx,
  76. [[maybe_unused]] std::string_view composite,
  77. [[maybe_unused]] u32 index) {
  78. throw NotImplementedException("GLSL Instruction");
  79. }
  80. void EmitCompositeInsertF16x2([[maybe_unused]] EmitContext& ctx,
  81. [[maybe_unused]] std::string_view composite,
  82. [[maybe_unused]] std::string_view object,
  83. [[maybe_unused]] u32 index) {
  84. throw NotImplementedException("GLSL Instruction");
  85. }
  86. void EmitCompositeInsertF16x3([[maybe_unused]] EmitContext& ctx,
  87. [[maybe_unused]] std::string_view composite,
  88. [[maybe_unused]] std::string_view object,
  89. [[maybe_unused]] u32 index) {
  90. throw NotImplementedException("GLSL Instruction");
  91. }
  92. void EmitCompositeInsertF16x4([[maybe_unused]] EmitContext& ctx,
  93. [[maybe_unused]] std::string_view composite,
  94. [[maybe_unused]] std::string_view object,
  95. [[maybe_unused]] u32 index) {
  96. throw NotImplementedException("GLSL Instruction");
  97. }
  98. void EmitCompositeConstructF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
  99. std::string_view e2) {
  100. ctx.AddF32x2("{}=vec2({},{});", inst, e1, e2);
  101. }
  102. void EmitCompositeConstructF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
  103. std::string_view e2, std::string_view e3) {
  104. ctx.AddF32x3("{}=vec3({},{},{});", inst, e1, e2, e3);
  105. }
  106. void EmitCompositeConstructF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
  107. std::string_view e2, std::string_view e3, std::string_view e4) {
  108. ctx.AddF32x4("{}=vec4({},{},{},{});", inst, e1, e2, e3, e4);
  109. }
  110. void EmitCompositeExtractF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
  111. u32 index) {
  112. ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
  113. }
  114. void EmitCompositeExtractF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
  115. u32 index) {
  116. ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
  117. }
  118. void EmitCompositeExtractF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
  119. u32 index) {
  120. ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
  121. }
  122. void EmitCompositeInsertF32x2(EmitContext& ctx, std::string_view composite, std::string_view object,
  123. u32 index) {
  124. ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
  125. }
  126. void EmitCompositeInsertF32x3(EmitContext& ctx, std::string_view composite, std::string_view object,
  127. u32 index) {
  128. ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
  129. }
  130. void EmitCompositeInsertF32x4(EmitContext& ctx, std::string_view composite, std::string_view object,
  131. u32 index) {
  132. ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
  133. }
  134. void EmitCompositeConstructF64x2([[maybe_unused]] EmitContext& ctx) {
  135. throw NotImplementedException("GLSL Instruction");
  136. }
  137. void EmitCompositeConstructF64x3([[maybe_unused]] EmitContext& ctx) {
  138. throw NotImplementedException("GLSL Instruction");
  139. }
  140. void EmitCompositeConstructF64x4([[maybe_unused]] EmitContext& ctx) {
  141. throw NotImplementedException("GLSL Instruction");
  142. }
  143. void EmitCompositeExtractF64x2([[maybe_unused]] EmitContext& ctx) {
  144. throw NotImplementedException("GLSL Instruction");
  145. }
  146. void EmitCompositeExtractF64x3([[maybe_unused]] EmitContext& ctx) {
  147. throw NotImplementedException("GLSL Instruction");
  148. }
  149. void EmitCompositeExtractF64x4([[maybe_unused]] EmitContext& ctx) {
  150. throw NotImplementedException("GLSL Instruction");
  151. }
  152. void EmitCompositeInsertF64x2(EmitContext& ctx, std::string_view composite, std::string_view object,
  153. u32 index) {
  154. ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
  155. }
  156. void EmitCompositeInsertF64x3(EmitContext& ctx, std::string_view composite, std::string_view object,
  157. u32 index) {
  158. ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
  159. }
  160. void EmitCompositeInsertF64x4(EmitContext& ctx, std::string_view composite, std::string_view object,
  161. u32 index) {
  162. ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
  163. }
  164. } // namespace Shader::Backend::GLSL