2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-11-29 07:47:48 +00:00

feat: dump material techniques for T6

This commit is contained in:
Jan Laupetin
2025-11-13 22:44:09 +00:00
parent 4e43f32f14
commit 466d7ab0f2
8 changed files with 221 additions and 36 deletions

View File

@@ -6,7 +6,6 @@
#include "Techset/CommonTechsetDumper.h"
#include "Techset/TechniqueDumpingZoneState.h"
#include <sstream>
#include <unordered_set>
using namespace T6;
@@ -102,18 +101,51 @@ namespace
techset::CommonTechnique ConvertToCommonTechnique(const MaterialTechnique& technique)
{
std::vector<std::string> techniqueNames(std::extent_v<decltype(techniqueTypeNames)>);
std::vector<techset::CommonPass> passes;
for (auto techniqueIndex = 0u; techniqueIndex < std::extent_v<decltype(techniqueTypeNames)>; techniqueIndex++)
for (auto passIndex = 0u; passIndex < technique.passCount; passIndex++)
{
const auto* technique = techset.techniques[techniqueIndex];
if (technique && technique->name)
techniqueNames[techniqueIndex] = technique->name;
const auto& pass = technique.passArray[passIndex];
techset::CommonTechniqueShader vertexShader{};
techset::CommonTechniqueShader pixelShader{};
if (pass.vertexShader)
{
if (pass.vertexShader->name)
vertexShader.m_name = pass.vertexShader->name;
if (pass.vertexShader->prog.loadDef.program)
{
vertexShader.m_shader_bin = pass.vertexShader->prog.loadDef.program;
vertexShader.m_shader_bin_size = pass.vertexShader->prog.loadDef.programSize * sizeof(uint32_t);
}
}
if (pass.pixelShader)
{
if (pass.pixelShader->name)
pixelShader.m_name = pass.pixelShader->name;
if (pass.pixelShader->prog.loadDef.program)
{
pixelShader.m_shader_bin = pass.pixelShader->prog.loadDef.program;
pixelShader.m_shader_bin_size = pass.pixelShader->prog.loadDef.programSize * sizeof(uint32_t);
}
}
passes.emplace_back(techset::CommonPass{
.m_sampler_flags = pass.customSamplerFlags,
.m_dx_version = techset::DxVersion::DX11,
.m_vertex_shader = vertexShader,
.m_pixel_shader = pixelShader,
});
}
return techset::CommonTechset{
.m_name = techset.name,
.m_technique_names = std::move(techniqueNames),
return techset::CommonTechnique{
.m_name = technique.name ? technique.name : std::string(),
.m_flags = technique.flags,
.m_passes = std::move(passes),
};
}

View File

@@ -0,0 +1,143 @@
#include "CommonTechniqueDumper.h"
#include "Dumping/AbstractTextDumper.h"
#include "Shader/D3D11ShaderAnalyser.h"
#include "Shader/D3D9ShaderAnalyser.h"
#include "Techset/TechsetCommon.h"
#include <cassert>
#include <cstdint>
using namespace techset;
namespace
{
enum class TechniqueShaderType : std::uint8_t
{
VERTEX_SHADER,
PIXEL_SHADER
};
class TechniqueFileWriter : public AbstractTextDumper
{
public:
explicit TechniqueFileWriter(std::ostream& stream)
: AbstractTextDumper(stream)
{
}
void DumpTechnique(const CommonTechnique& technique)
{
#ifdef TECHSET_DEBUG
if (technique.m_flags)
{
for (auto i = 0u; i < sizeof(CommonTechnique::m_flags) * 8u; i++)
{
const auto mask = 1ui64 << i;
if (technique.m_flags & mask)
{
Indent();
m_stream << std::format("// TECHNIQUE FLAGS: 0x{:x}\n", mask);
}
}
}
#endif
for (const auto& pass : technique.m_passes)
DumpPass(pass);
}
private:
void DumpPass(const CommonPass& pass)
{
m_stream << "{\n";
IncIndent();
#ifdef TECHSET_DEBUG
for (auto i = 0u; i < sizeof(CommonPass::m_sampler_flags) * 8u; i++)
{
const auto mask = 1ui64 << i;
if (pass.m_sampler_flags & mask)
{
Indent();
m_stream << std::format("// CUSTOM SAMPLER FLAGS: 0x{:x}\n", mask);
}
}
#endif
DumpStateMap();
DumpShader(pass, pass.m_vertex_shader, TechniqueShaderType::VERTEX_SHADER);
DumpShader(pass, pass.m_pixel_shader, TechniqueShaderType::PIXEL_SHADER);
// DumpVertexDecl(pass);
DecIndent();
m_stream << "}\n";
}
void DumpStateMap() const
{
Indent();
// TODO: Actual statemap: Maybe find all materials using this techset and try to make out rules
// for the flags based on the statebitstable
m_stream << "stateMap \"passthrough\"; // TODO\n";
}
void DumpShader(const CommonPass& pass, const CommonTechniqueShader& shader, const TechniqueShaderType shaderType) const
{
if (!shader.m_shader_bin)
{
if (!shader.m_name.empty())
m_stream << std::format("// Cannot dump shader {} as its data is not loaded\n", shader.m_name);
return;
}
unsigned versionMajor, versionMinor;
if (pass.m_dx_version == DxVersion::DX9)
{
const auto shaderInfo = d3d9::ShaderAnalyser::GetShaderInfo(shader.m_shader_bin, shader.m_shader_bin_size);
assert(shaderInfo);
if (!shaderInfo)
return;
versionMajor = shaderInfo->m_version_major;
versionMinor = shaderInfo->m_version_minor;
}
else
{
assert(pass.m_dx_version == DxVersion::DX11);
const auto shaderInfo = d3d11::ShaderAnalyser::GetShaderInfo(shader.m_shader_bin, shader.m_shader_bin_size);
assert(shaderInfo);
if (!shaderInfo)
return;
versionMajor = shaderInfo->m_version_major;
versionMinor = shaderInfo->m_version_minor;
}
const auto shaderTypeName = shaderType == TechniqueShaderType::VERTEX_SHADER ? "vertexShader" : "pixelShader";
m_stream << "\n";
Indent();
m_stream << std::format("{} {}.{} \"{}\"\n", shaderTypeName, versionMajor, versionMinor, shader.m_name);
Indent();
m_stream << "{\n";
Indent();
m_stream << "}\n";
}
};
} // namespace
namespace techset
{
void DumpCommonTechnique(const AssetDumpingContext& context, const CommonTechnique& technique)
{
const auto techniqueFile = context.OpenAssetFile(GetFileNameForTechniqueName(technique.m_name));
if (techniqueFile)
{
TechniqueFileWriter writer(*techniqueFile);
writer.DumpTechnique(technique);
}
}
} // namespace techset

View File

@@ -1,9 +1,9 @@
#pragma once
#include "Dumping/AssetDumpingContext.h"
#include "Techset/CommonTechset.h"
#include "Techset/CommonTechnique.h"
namespace techset
{
void DumpCommonTechnique(const AssetDumpingContext& context, const CommonTechset& techset);
void DumpCommonTechnique(const AssetDumpingContext& context, const CommonTechnique& technique);
} // namespace techset

View File

@@ -1,7 +1,6 @@
#include "CommonTechsetDumper.h"
#include "Dumping/AbstractTextDumper.h"
#include "Game/IW3/Material/MaterialConstantZoneStateIW3.h"
#include "Techset/TechsetCommon.h"
#include <cassert>
@@ -36,8 +35,7 @@ namespace
dumpedTechniques[techniqueIndex] = true;
WriteTechniqueType(techniqueIndex);
for (auto nextTechniqueIndex = techniqueIndex + 1; nextTechniqueIndex < std::extent_v<decltype(IW3::MaterialTechniqueSet::techniques)>;
nextTechniqueIndex++)
for (auto nextTechniqueIndex = techniqueIndex + 1; nextTechniqueIndex < techniqueCount; nextTechniqueIndex++)
{
if (techset.m_technique_names[nextTechniqueIndex] != technique)
continue;