[tools] add separate maxwell disassembler, ir dumper, and spirv translator (#3453)

why not?

Signed-off-by: lizzie <lizzie@eden-emu.dev>

Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3453
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
This commit is contained in:
lizzie 2026-05-24 01:05:07 +02:00 committed by crueter
parent 2aa2ac7d9a
commit d9067d85af
No known key found for this signature in database
GPG key ID: 425ACD2D4830EBC6
12 changed files with 1137 additions and 1 deletions

View file

@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
# SPDX-License-Identifier: GPL-3.0-or-later
add_executable(maxwell-spirv
main.cpp
spirv_recompiler_impl.cpp
spirv_reference_impl.cpp
)
target_link_libraries(maxwell-spirv PRIVATE common shader_recompiler Threads::Threads)
target_include_directories(maxwell-spirv PRIVATE ${CMAKE_SOURCE_DIR}/src)
if(UNIX AND NOT APPLE)
install(TARGETS maxwell-spirv)
endif()
create_target_directory_groups(maxwell-spirv)

View file

@ -0,0 +1,26 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include <cstdio>
#include <cstdlib>
#include <cstring>
int SpirvReferenceImpl(int argc, char *argv[]);
int SpirvShaderRecompilerImpl(int argc, char *argv[]);
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("usage: %s [input file]\n"
"Specify -n to use a recompiler that is NOT tied to the shader recompiler\n"
"aka. a reference recompiler\n"
"RAW SPIRV CODE WILL BE SENT TO STDOUT!\n", argv[0]);
return EXIT_FAILURE;
}
if (argc >= 3) {
if (::strcmp(argv[2], "-n") == 0
|| ::strcmp(argv[2], "--new") == 0) {
return SpirvReferenceImpl(argc, argv);
}
}
return SpirvShaderRecompilerImpl(argc, argv);
}

View file

@ -0,0 +1,67 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include <cstdlib>
#include <sys/stat.h>
#include "shader_recompiler/backend/spirv/emit_spirv.h"
#include "shader_recompiler/environment.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 "shader_recompiler/profile.h"
#include "shader_recompiler/runtime_info.h"
#include "../maxwell-disas/file_environment.h"
int SpirvShaderRecompilerImpl(int argc, char *argv[]) {
if (argc != 2) {
printf("usage: %s [input file] [-n]\n"
"RAW SPIRV CODE WILL BE SENT TO STDOUT!\n", argv[0]);
return EXIT_FAILURE;
}
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;
auto program = Shader::Maxwell::TranslateProgram(inst_pool, block_pool, env, cfg, host_info);
// IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool,
// Environment& env, Flow::CFG& cfg, const HostTranslateInfo& host_info)
// std::vector<u32> EmitSPIRV(const Profile& profile, const RuntimeInfo& runtime_info,
// IR::Program& program, Bindings& bindings, bool optimize)
Shader::Profile profile{};
Shader::RuntimeInfo runtime_info;
auto const spirv_pgm = Shader::Backend::SPIRV::EmitSPIRV(profile, program, true);
fwrite(spirv_pgm.data(), sizeof(u64), spirv_pgm.size(), stdout);
return EXIT_SUCCESS;
}

View file

@ -0,0 +1,15 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "common/bit_field.h"
#include "common/common_types.h"
#include "spirv/unified1/spirv.hpp11"
#include <cassert>
#include <cstdlib>
#include <sirit/sirit.h>
#include <sys/stat.h>
int ReferenceImpl(int argc, char *argv[]) {
//todo
return EXIT_SUCCESS;
}