emit_context.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2021 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <string>
  6. #include <utility>
  7. #include <vector>
  8. #include <fmt/format.h>
  9. #include "shader_recompiler/backend/glasm/reg_alloc.h"
  10. #include "shader_recompiler/stage.h"
  11. namespace Shader {
  12. struct Info;
  13. struct Profile;
  14. struct RuntimeInfo;
  15. } // namespace Shader
  16. namespace Shader::Backend {
  17. struct Bindings;
  18. }
  19. namespace Shader::IR {
  20. class Inst;
  21. struct Program;
  22. } // namespace Shader::IR
  23. namespace Shader::Backend::GLASM {
  24. class EmitContext {
  25. public:
  26. explicit EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_,
  27. const RuntimeInfo& runtime_info_);
  28. template <typename... Args>
  29. void Add(const char* format_str, IR::Inst& inst, Args&&... args) {
  30. code += fmt::format(fmt::runtime(format_str), reg_alloc.Define(inst),
  31. std::forward<Args>(args)...);
  32. // TODO: Remove this
  33. code += '\n';
  34. }
  35. template <typename... Args>
  36. void LongAdd(const char* format_str, IR::Inst& inst, Args&&... args) {
  37. code += fmt::format(fmt::runtime(format_str), reg_alloc.LongDefine(inst),
  38. std::forward<Args>(args)...);
  39. // TODO: Remove this
  40. code += '\n';
  41. }
  42. template <typename... Args>
  43. void Add(const char* format_str, Args&&... args) {
  44. code += fmt::format(fmt::runtime(format_str), std::forward<Args>(args)...);
  45. // TODO: Remove this
  46. code += '\n';
  47. }
  48. std::string code;
  49. RegAlloc reg_alloc{};
  50. const Info& info;
  51. const Profile& profile;
  52. const RuntimeInfo& runtime_info;
  53. std::vector<u32> texture_buffer_bindings;
  54. std::vector<u32> image_buffer_bindings;
  55. std::vector<u32> texture_bindings;
  56. std::vector<u32> image_bindings;
  57. Stage stage{};
  58. std::string_view stage_name = "invalid";
  59. std::string_view attrib_name = "invalid";
  60. u32 num_safety_loop_vars{};
  61. bool uses_y_direction{};
  62. };
  63. } // namespace Shader::Backend::GLASM