emit_context.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. } // namespace Shader
  15. namespace Shader::Backend {
  16. struct Bindings;
  17. }
  18. namespace Shader::IR {
  19. class Inst;
  20. struct Program;
  21. } // namespace Shader::IR
  22. namespace Shader::Backend::GLASM {
  23. class EmitContext {
  24. public:
  25. explicit EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_);
  26. template <typename... Args>
  27. void Add(const char* format_str, IR::Inst& inst, Args&&... args) {
  28. code += fmt::format(format_str, reg_alloc.Define(inst), std::forward<Args>(args)...);
  29. // TODO: Remove this
  30. code += '\n';
  31. }
  32. template <typename... Args>
  33. void LongAdd(const char* format_str, IR::Inst& inst, Args&&... args) {
  34. code += fmt::format(format_str, reg_alloc.LongDefine(inst), std::forward<Args>(args)...);
  35. // TODO: Remove this
  36. code += '\n';
  37. }
  38. template <typename... Args>
  39. void Add(const char* format_str, Args&&... args) {
  40. code += fmt::format(format_str, std::forward<Args>(args)...);
  41. // TODO: Remove this
  42. code += '\n';
  43. }
  44. std::string code;
  45. RegAlloc reg_alloc{*this};
  46. const Info& info;
  47. const Profile& profile;
  48. std::vector<u32> texture_buffer_bindings;
  49. std::vector<u32> image_buffer_bindings;
  50. std::vector<u32> texture_bindings;
  51. std::vector<u32> image_bindings;
  52. Stage stage{};
  53. std::string_view stage_name = "invalid";
  54. };
  55. } // namespace Shader::Backend::GLASM