summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/shader_recompiler/CMakeLists.txt6
-rw-r--r--src/shader_recompiler/file_environment.cpp50
-rw-r--r--src/shader_recompiler/file_environment.h25
-rw-r--r--src/shader_recompiler/main.cpp95
4 files changed, 0 insertions, 176 deletions
diff --git a/src/shader_recompiler/CMakeLists.txt b/src/shader_recompiler/CMakeLists.txt
index 151733090..f20031d98 100644
--- a/src/shader_recompiler/CMakeLists.txt
+++ b/src/shader_recompiler/CMakeLists.txt
@@ -22,8 +22,6 @@ add_library(shader_recompiler STATIC
22 backend/spirv/emit_spirv_warp.cpp 22 backend/spirv/emit_spirv_warp.cpp
23 environment.h 23 environment.h
24 exception.h 24 exception.h
25 file_environment.cpp
26 file_environment.h
27 frontend/ir/attribute.cpp 25 frontend/ir/attribute.cpp
28 frontend/ir/attribute.h 26 frontend/ir/attribute.h
29 frontend/ir/basic_block.cpp 27 frontend/ir/basic_block.cpp
@@ -178,9 +176,6 @@ add_library(shader_recompiler STATIC
178 176
179target_link_libraries(shader_recompiler PUBLIC common fmt::fmt sirit) 177target_link_libraries(shader_recompiler PUBLIC common fmt::fmt sirit)
180 178
181add_executable(shader_util main.cpp)
182target_link_libraries(shader_util PRIVATE shader_recompiler)
183
184if (MSVC) 179if (MSVC)
185 target_compile_options(shader_recompiler PRIVATE 180 target_compile_options(shader_recompiler PRIVATE
186 /W4 181 /W4
@@ -213,4 +208,3 @@ else()
213endif() 208endif()
214 209
215create_target_directory_groups(shader_recompiler) 210create_target_directory_groups(shader_recompiler)
216create_target_directory_groups(shader_util)
diff --git a/src/shader_recompiler/file_environment.cpp b/src/shader_recompiler/file_environment.cpp
deleted file mode 100644
index f2104f444..000000000
--- a/src/shader_recompiler/file_environment.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
1#include <cstdio>
2
3#include "exception.h"
4#include "file_environment.h"
5
6namespace Shader {
7
8FileEnvironment::FileEnvironment(const char* path) {
9 std::FILE* const file{std::fopen(path, "rb")};
10 if (!file) {
11 throw RuntimeError("Failed to open file='{}'", path);
12 }
13 std::fseek(file, 0, SEEK_END);
14 const long size{std::ftell(file)};
15 std::rewind(file);
16 if (size % 8 != 0) {
17 std::fclose(file);
18 throw RuntimeError("File size={} is not aligned to 8", size);
19 }
20 // TODO: Use a unique_ptr to avoid zero-initializing this
21 const size_t num_inst{static_cast<size_t>(size) / 8};
22 data.resize(num_inst);
23 if (std::fread(data.data(), 8, num_inst, file) != num_inst) {
24 std::fclose(file);
25 throw RuntimeError("Failed to read instructions={} from file='{}'", num_inst, path);
26 }
27 std::fclose(file);
28}
29
30FileEnvironment::~FileEnvironment() = default;
31
32u64 FileEnvironment::ReadInstruction(u32 offset) {
33 if (offset % 8 != 0) {
34 throw InvalidArgument("offset={} is not aligned to 8", offset);
35 }
36 if (offset / 8 >= static_cast<u32>(data.size())) {
37 throw InvalidArgument("offset={} is out of bounds", offset);
38 }
39 return data[offset / 8];
40}
41
42u32 FileEnvironment::TextureBoundBuffer() const {
43 throw NotImplementedException("Texture bound buffer serialization");
44}
45
46std::array<u32, 3> FileEnvironment::WorkgroupSize() const {
47 return {1, 1, 1};
48}
49
50} // namespace Shader
diff --git a/src/shader_recompiler/file_environment.h b/src/shader_recompiler/file_environment.h
deleted file mode 100644
index 71601f8fd..000000000
--- a/src/shader_recompiler/file_environment.h
+++ /dev/null
@@ -1,25 +0,0 @@
1#pragma once
2
3#include <vector>
4
5#include "common/common_types.h"
6#include "shader_recompiler/environment.h"
7
8namespace Shader {
9
10class FileEnvironment : public Environment {
11public:
12 explicit FileEnvironment(const char* path);
13 ~FileEnvironment() override;
14
15 u64 ReadInstruction(u32 offset) override;
16
17 u32 TextureBoundBuffer() const override;
18
19 std::array<u32, 3> WorkgroupSize() const override;
20
21private:
22 std::vector<u64> data;
23};
24
25} // namespace Shader
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}