2023-10-13 15:00:08 -04:00
|
|
|
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
#include "shpkpart.h"
|
|
|
|
#include "dxbc_module.h"
|
|
|
|
#include "dxbc_reader.h"
|
2024-02-04 15:25:14 -05:00
|
|
|
#include <KLocalizedString>
|
2023-10-13 15:00:08 -04:00
|
|
|
#include <QTextEdit>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <spirv_glsl.hpp>
|
|
|
|
|
2023-12-09 21:28:02 -05:00
|
|
|
SHPKPart::SHPKPart(GameData *data, QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, data(data)
|
2023-10-13 15:00:08 -04:00
|
|
|
{
|
|
|
|
auto layout = new QVBoxLayout();
|
|
|
|
setLayout(layout);
|
|
|
|
|
|
|
|
pageTabWidget = new QTabWidget();
|
|
|
|
layout->addWidget(pageTabWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SHPKPart::load(physis_Buffer buffer)
|
|
|
|
{
|
|
|
|
auto shader = physis_parse_shpk(buffer);
|
|
|
|
|
|
|
|
pageTabWidget->clear();
|
|
|
|
|
2023-12-09 15:24:54 -05:00
|
|
|
const auto addShader = [this](physis_Shader shader, const QString &name) {
|
2023-10-13 15:00:08 -04:00
|
|
|
auto shaderTextEdit = new QTextEdit();
|
|
|
|
shaderTextEdit->setReadOnly(true);
|
|
|
|
|
2024-04-20 15:45:19 -04:00
|
|
|
try {
|
|
|
|
dxvk::DxbcReader reader(reinterpret_cast<const char *>(shader.bytecode), shader.len);
|
2023-10-13 15:00:08 -04:00
|
|
|
|
2024-04-20 15:45:19 -04:00
|
|
|
dxvk::DxbcModule module(reader);
|
2023-10-13 15:00:08 -04:00
|
|
|
|
2024-04-20 15:45:19 -04:00
|
|
|
dxvk::DxbcModuleInfo info;
|
|
|
|
auto result = module.compile(info, "test");
|
2023-10-13 15:00:08 -04:00
|
|
|
|
2024-04-20 15:45:19 -04:00
|
|
|
spirv_cross::CompilerGLSL glsl(result.code.data(), result.code.dwords());
|
2023-10-13 15:00:08 -04:00
|
|
|
|
2024-04-20 15:45:19 -04:00
|
|
|
glsl.build_combined_image_samplers();
|
2023-10-13 15:00:08 -04:00
|
|
|
|
2024-04-20 15:45:19 -04:00
|
|
|
spirv_cross::CompilerGLSL::Options options;
|
|
|
|
options.version = 310;
|
|
|
|
options.vulkan_semantics = true;
|
|
|
|
glsl.set_common_options(options);
|
2023-10-13 15:00:08 -04:00
|
|
|
|
2024-04-20 15:45:19 -04:00
|
|
|
shaderTextEdit->setText(QLatin1String(glsl.compile().c_str()));
|
2023-10-13 15:00:08 -04:00
|
|
|
|
2024-04-20 15:45:19 -04:00
|
|
|
pageTabWidget->addTab(shaderTextEdit, name);
|
|
|
|
} catch (std::exception exception) {
|
|
|
|
// TODO: display the error
|
|
|
|
}
|
2023-10-13 15:00:08 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = 0; i < shader.num_vertex_shaders; i++) {
|
2024-04-20 15:45:19 -04:00
|
|
|
addShader(shader.vertex_shaders[i], i18nc("@title:tab", "Vertex Shader %1", i));
|
2023-10-13 15:00:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < shader.num_pixel_shaders; i++) {
|
2024-04-20 15:45:19 -04:00
|
|
|
addShader(shader.pixel_shaders[i], i18nc("@title:tab", "Pixel Shader %1", i));
|
2023-10-13 15:00:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_shpkpart.cpp"
|