emit_context.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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(format_str, reg_alloc.Define(inst), std::forward<Args>(args)...);
  31. // TODO: Remove this
  32. code += '\n';
  33. }
  34. template <typename... Args>
  35. void LongAdd(const char* format_str, IR::Inst& inst, Args&&... args) {
  36. code += fmt::format(format_str, reg_alloc.LongDefine(inst), std::forward<Args>(args)...);
  37. // TODO: Remove this
  38. code += '\n';
  39. }
  40. template <typename... Args>
  41. void Add(const char* format_str, Args&&... args) {
  42. code += fmt::format(format_str, std::forward<Args>(args)...);
  43. // TODO: Remove this
  44. code += '\n';
  45. }
  46. std::string code;
  47. RegAlloc reg_alloc{*this};
  48. const Info& info;
  49. const Profile& profile;
  50. const RuntimeInfo& runtime_info;
  51. std::vector<u32> texture_buffer_bindings;
  52. std::vector<u32> image_buffer_bindings;
  53. std::vector<u32> texture_bindings;
  54. std::vector<u32> image_bindings;
  55. Stage stage{};
  56. std::string_view stage_name = "invalid";
  57. std::string_view attrib_name = "invalid";
  58. bool uses_y_direction{};
  59. };
  60. } // namespace Shader::Backend::GLASM