main.cpp 2.8 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. #include <chrono>
  5. #include <filesystem>
  6. #include <fmt/format.h>
  7. #include "shader_recompiler/backend/spirv/emit_spirv.h"
  8. #include "shader_recompiler/file_environment.h"
  9. #include "shader_recompiler/frontend/ir/basic_block.h"
  10. #include "shader_recompiler/frontend/ir/ir_emitter.h"
  11. #include "shader_recompiler/frontend/maxwell/control_flow.h"
  12. #include "shader_recompiler/frontend/maxwell/decode.h"
  13. #include "shader_recompiler/frontend/maxwell/location.h"
  14. #include "shader_recompiler/frontend/maxwell/program.h"
  15. #include "shader_recompiler/frontend/maxwell/translate/translate.h"
  16. using namespace Shader;
  17. using namespace Shader::Maxwell;
  18. template <typename Func>
  19. static void ForEachFile(const std::filesystem::path& path, Func&& func) {
  20. std::filesystem::directory_iterator end;
  21. for (std::filesystem::directory_iterator it{path}; it != end; ++it) {
  22. if (std::filesystem::is_directory(*it)) {
  23. ForEachFile(*it, func);
  24. } else {
  25. func(*it);
  26. }
  27. }
  28. }
  29. void RunDatabase() {
  30. std::vector<std::unique_ptr<FileEnvironment>> map;
  31. ForEachFile("D:\\Shaders\\Database", [&](const std::filesystem::path& path) {
  32. map.emplace_back(std::make_unique<FileEnvironment>(path.string().c_str()));
  33. });
  34. ObjectPool<Flow::Block> block_pool;
  35. using namespace std::chrono;
  36. auto t0 = high_resolution_clock::now();
  37. int N = 1;
  38. int n = 0;
  39. for (int i = 0; i < N; ++i) {
  40. for (auto& env : map) {
  41. ++n;
  42. // fmt::print(stdout, "Decoding {}\n", path.string());
  43. const Location start_address{0};
  44. block_pool.ReleaseContents();
  45. Flow::CFG cfg{*env, block_pool, start_address};
  46. // fmt::print(stdout, "{}\n", cfg->Dot());
  47. // IR::Program program{env, cfg};
  48. // Optimize(program);
  49. // const std::string code{EmitGLASM(program)};
  50. }
  51. }
  52. auto t = high_resolution_clock::now();
  53. fmt::print(stdout, "{} ms", duration_cast<milliseconds>(t - t0).count() / double(N));
  54. }
  55. int main() {
  56. // RunDatabase();
  57. ObjectPool<Flow::Block> flow_block_pool;
  58. ObjectPool<IR::Inst> inst_pool;
  59. ObjectPool<IR::Block> block_pool;
  60. FileEnvironment env{"D:\\Shaders\\Database\\Oninaki\\CS8F146B41DB6BD826.bin"};
  61. // FileEnvironment env{"D:\\Shaders\\shader.bin"};
  62. block_pool.ReleaseContents();
  63. inst_pool.ReleaseContents();
  64. flow_block_pool.ReleaseContents();
  65. Flow::CFG cfg{env, flow_block_pool, 0};
  66. fmt::print(stdout, "{}\n", cfg.Dot());
  67. IR::Program program{TranslateProgram(inst_pool, block_pool, env, cfg)};
  68. fmt::print(stdout, "{}\n", IR::DumpProgram(program));
  69. void(Backend::SPIRV::EmitSPIRV(env, program));
  70. }