summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/main.cpp')
-rw-r--r--src/shader_recompiler/main.cpp95
1 files changed, 0 insertions, 95 deletions
diff --git a/src/shader_recompiler/main.cpp b/src/shader_recompiler/main.cpp
deleted file mode 100644
index 72565f477..000000000
--- a/src/shader_recompiler/main.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <chrono>
6#include <filesystem>
7
8#include <fmt/format.h>
9
10#include "shader_recompiler/backend/spirv/emit_spirv.h"
11#include "shader_recompiler/file_environment.h"
12#include "shader_recompiler/frontend/ir/basic_block.h"
13#include "shader_recompiler/frontend/ir/ir_emitter.h"
14#include "shader_recompiler/frontend/maxwell/control_flow.h"
15#include "shader_recompiler/frontend/maxwell/decode.h"
16#include "shader_recompiler/frontend/maxwell/location.h"
17#include "shader_recompiler/frontend/maxwell/program.h"
18#include "shader_recompiler/frontend/maxwell/translate/translate.h"
19
20using namespace Shader;
21using namespace Shader::Maxwell;
22
23template <typename Func>
24static void ForEachFile(const std::filesystem::path& path, Func&& func) {
25 std::filesystem::directory_iterator end;
26 for (std::filesystem::directory_iterator it{path}; it != end; ++it) {
27 if (std::filesystem::is_directory(*it)) {
28 ForEachFile(*it, func);
29 } else {
30 func(*it);
31 }
32 }
33}
34
35void RunDatabase() {
36 std::vector<std::unique_ptr<FileEnvironment>> map;
37 ForEachFile("D:\\Shaders\\Database", [&](const std::filesystem::path& path) {
38 map.emplace_back(std::make_unique<FileEnvironment>(path.string().c_str()));
39 });
40 ObjectPool<Flow::Block> block_pool;
41 using namespace std::chrono;
42 auto t0 = high_resolution_clock::now();
43 int N = 1;
44 int n = 0;
45 for (int i = 0; i < N; ++i) {
46 for (auto& env : map) {
47 ++n;
48 // fmt::print(stdout, "Decoding {}\n", path.string());
49
50 const Location start_address{0};
51 block_pool.ReleaseContents();
52 Flow::CFG cfg{*env, block_pool, start_address};
53 // fmt::print(stdout, "{}\n", cfg->Dot());
54 // IR::Program program{env, cfg};
55 // Optimize(program);
56 // const std::string code{EmitGLASM(program)};
57 }
58 }
59 auto t = high_resolution_clock::now();
60 fmt::print(stdout, "{} ms", duration_cast<milliseconds>(t - t0).count() / double(N));
61}
62
63static constexpr Profile PROFILE{
64 .unified_descriptor_binding = true,
65 .support_float_controls = true,
66 .support_separate_denorm_behavior = true,
67 .support_separate_rounding_mode = true,
68 .support_fp16_denorm_preserve = true,
69 .support_fp32_denorm_preserve = true,
70 .support_fp16_denorm_flush = true,
71 .support_fp32_denorm_flush = true,
72};
73
74int main() {
75 // RunDatabase();
76
77 ObjectPool<Flow::Block> flow_block_pool;
78 ObjectPool<IR::Inst> inst_pool;
79 ObjectPool<IR::Block> block_pool;
80
81 // FileEnvironment env{"D:\\Shaders\\Database\\Oninaki\\CS8F146B41DB6BD826.bin"};
82 FileEnvironment env{"D:\\Shaders\\shader.bin"};
83 block_pool.ReleaseContents();
84 inst_pool.ReleaseContents();
85 flow_block_pool.ReleaseContents();
86 Flow::CFG cfg{env, flow_block_pool, 0};
87 fmt::print(stdout, "{}\n", cfg.Dot());
88 IR::Program program{TranslateProgram(inst_pool, block_pool, env, cfg)};
89 fmt::print(stdout, "{}\n", IR::DumpProgram(program));
90 const std::vector<u32> spirv{Backend::SPIRV::EmitSPIRV(PROFILE, env, program)};
91 std::FILE* const file{std::fopen("D:\\shader.spv", "wb")};
92 std::fwrite(spirv.data(), spirv.size(), sizeof(u32), file);
93 std::fclose(file);
94 std::system("spirv-dis D:\\shader.spv");
95}