aboutsummaryrefslogtreecommitdiff
path: root/tools/maxwell-ir/main.cpp
blob: 645816878df475bf45c0587164890d4783f71563 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later

#include <cstdio>
#include <cstdlib>
#include <cstring>

#include "shader_recompiler/frontend/ir/basic_block.h"
#include "shader_recompiler/frontend/maxwell/control_flow.h"
#include "shader_recompiler/frontend/maxwell/translate_program.h"
#include "shader_recompiler/host_translate_info.h"
#include "shader_recompiler/object_pool.h"
#include "../maxwell-disas/file_environment.h"

int IrShaderRecompilerImpl(int argc, char *argv[]) {
    size_t cfg_offset = 0;

    Shader::ObjectPool<Shader::IR::Inst> inst_pool;
    Shader::ObjectPool<Shader::IR::Block> block_pool;
    Shader::ObjectPool<Shader::Maxwell::Flow::Block> cfg_blocks;
    FileEnvironment env;

    FILE *fp = fopen(argv[1], "rb");
    if (fp != NULL) {
        struct stat st;
        fstat(fileno(fp), &st);
        auto const words = (st.st_size / sizeof(u64));
        env.code.resize(words + 1);
        fread(env.code.data(), sizeof(u64), words, fp);
        fclose(fp);
    }

    env.read_highest = env.read_lowest + env.code.size() * sizeof(u64);

    Shader::Maxwell::Flow::CFG cfg(env, cfg_blocks, cfg_offset);

    Shader::HostTranslateInfo host_info;
    host_info.support_float64 = true;
    host_info.support_float16 = true;
    host_info.support_int64 = true;
    host_info.needs_demote_reorder = true;
    host_info.support_snorm_render_buffer = true;
    host_info.support_viewport_index_layer = true;
    host_info.support_geometry_shader_passthrough = true;
    host_info.support_conditional_barrier = true;
    host_info.min_ssbo_alignment = 0;
    host_info.ApplyDescriptorLimitPolicy();
    auto program = Shader::Maxwell::TranslateProgram(inst_pool, block_pool, env, cfg, host_info);
    auto const dumped_ir = Shader::IR::DumpProgram(program);
    std::printf("%s\n", dumped_ir.c_str());
    return EXIT_SUCCESS;
}

int main(int argc, char *argv[]) {
    if (argc < 2) {
        printf("usage: %s [input file]\n", argv[0]);
        return EXIT_FAILURE;
    }
    return IrShaderRecompilerImpl(argc, argv);
}