macro.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/assert.h"
  5. #include "common/logging/log.h"
  6. #include "core/settings.h"
  7. #include "video_core/macro/macro.h"
  8. #include "video_core/macro/macro_interpreter.h"
  9. #include "video_core/macro/macro_jit_x64.h"
  10. namespace Tegra {
  11. void MacroEngine::AddCode(u32 method, u32 data) {
  12. uploaded_macro_code[method].push_back(data);
  13. }
  14. void MacroEngine::Execute(u32 method, std::vector<u32> parameters) {
  15. auto compiled_macro = macro_cache.find(method);
  16. if (compiled_macro != macro_cache.end()) {
  17. compiled_macro->second->Execute(parameters, method);
  18. } else {
  19. // Macro not compiled, check if it's uploaded and if so, compile it
  20. auto macro_code = uploaded_macro_code.find(method);
  21. if (macro_code == uploaded_macro_code.end()) {
  22. UNREACHABLE_MSG("Macro 0x{0:x} was not uploaded", method);
  23. return;
  24. }
  25. macro_cache[method] = Compile(macro_code->second);
  26. macro_cache[method]->Execute(parameters, method);
  27. }
  28. }
  29. std::unique_ptr<MacroEngine> GetMacroEngine(Engines::Maxwell3D& maxwell3d) {
  30. if (Settings::values.disable_macro_jit) {
  31. return std::make_unique<MacroInterpreter>(maxwell3d);
  32. }
  33. #ifdef ARCHITECTURE_x86_64
  34. return std::make_unique<MacroJITx64>(maxwell3d);
  35. #else
  36. return std::make_unique<MacroInterpreter>(maxwell3d);
  37. #endif
  38. }
  39. } // namespace Tegra