2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-08-30 21:53:15 +00:00

refactor: streamline techset dumper

This commit is contained in:
Jan Laupetin
2025-07-30 23:22:18 +01:00
parent e26c66ed60
commit ea1c232164
13 changed files with 216 additions and 180 deletions

View File

@@ -0,0 +1,16 @@
#include "ShaderCommon.h"
#include <format>
namespace shader
{
std::string GetFileNameForPixelShaderAssetName(const std::string& assetName)
{
return std::format("shader_bin/ps_{}.cso", assetName);
}
std::string GetFileNameForVertexShaderAssetName(const std::string& assetName)
{
return std::format("shader_bin/vs_{}.cso", assetName);
}
} // namespace phys_constraints

View File

@@ -0,0 +1,9 @@
#pragma once
#include <string>
namespace shader
{
std::string GetFileNameForPixelShaderAssetName(const std::string& assetName);
std::string GetFileNameForVertexShaderAssetName(const std::string& assetName);
} // namespace shader

View File

@@ -0,0 +1,16 @@
#include "TechsetCommon.h"
#include <format>
namespace techset
{
std::string GetFileNameForTechniqueName(const std::string& assetName)
{
return std::format("techniques/{}.tech", assetName);
}
std::string GetFileNameForTechsetName(const std::string& assetName)
{
return std::format("techsets/{}.techset", assetName);
}
} // namespace phys_constraints

View File

@@ -0,0 +1,9 @@
#pragma once
#include <string>
namespace techset
{
std::string GetFileNameForTechniqueName(const std::string& assetName);
std::string GetFileNameForTechsetName(const std::string& assetName);
}

View File

@@ -21,7 +21,7 @@
#include "Sound/AssetDumperSndCurve.h"
#include "StringTable/StringTableDumperIW4.h"
#include "StructuredDataDef/AssetDumperStructuredDataDefSet.h"
#include "Techset/AssetDumperTechniqueSet.h"
#include "Techset/TechsetDumperIW4.h"
#include "Tracer/AssetDumperTracer.h"
#include "Vehicle/AssetDumperVehicle.h"
#include "Weapon/AssetDumperWeapon.h"
@@ -49,7 +49,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
#endif
DUMP_ASSET_POOL(AssetDumperPixelShader, m_material_pixel_shader, ASSET_TYPE_PIXELSHADER)
DUMP_ASSET_POOL(AssetDumperVertexShader, m_material_vertex_shader, ASSET_TYPE_VERTEXSHADER)
DUMP_ASSET_POOL(AssetDumperTechniqueSet, m_technique_set, ASSET_TYPE_TECHNIQUE_SET)
DUMP_ASSET_POOL(techset::Dumper, m_technique_set, ASSET_TYPE_TECHNIQUE_SET)
DUMP_ASSET_POOL(image::Dumper, m_image, ASSET_TYPE_IMAGE)
// DUMP_ASSET_POOL(AssetDumpersnd_alias_list_t, m_sound, ASSET_TYPE_SOUND)
DUMP_ASSET_POOL(AssetDumperSndCurve, m_sound_curve, ASSET_TYPE_SOUND_CURVE)

View File

@@ -1,17 +0,0 @@
#pragma once
#include "Dumping/AbstractAssetDumper.h"
#include "Game/IW4/IW4.h"
namespace IW4
{
class AssetDumperTechniqueSet final : public AbstractAssetDumper<MaterialTechniqueSet>
{
static std::string GetTechniqueFileName(const MaterialTechnique* technique);
static std::string GetTechsetFileName(const MaterialTechniqueSet* techset);
protected:
bool ShouldDump(XAssetInfo<MaterialTechniqueSet>* asset) override;
void DumpAsset(AssetDumpingContext& context, XAssetInfo<MaterialTechniqueSet>* asset) override;
};
} // namespace IW4

View File

@@ -1,9 +1,10 @@
#include "AssetDumperTechniqueSet.h"
#include "TechsetDumperIW4.h"
#include "Dumping/AbstractTextDumper.h"
#include "Game/IW4/TechsetConstantsIW4.h"
#include "Pool/GlobalAssetPool.h"
#include "Shader/D3D9ShaderAnalyser.h"
#include "Techset/TechsetCommon.h"
#include <algorithm>
#include <cassert>
@@ -12,6 +13,7 @@
#include <type_traits>
using namespace IW4;
using namespace ::techset;
namespace IW4
{
@@ -531,48 +533,37 @@ namespace IW4
};
} // namespace IW4
std::string AssetDumperTechniqueSet::GetTechniqueFileName(const MaterialTechnique* technique)
namespace IW4::techset
{
std::ostringstream ss;
ss << "techniques/" << technique->name << ".tech";
return ss.str();
}
std::string AssetDumperTechniqueSet::GetTechsetFileName(const MaterialTechniqueSet* techset)
{
std::ostringstream ss;
ss << "techsets/" << techset->name << ".techset";
return ss.str();
}
bool AssetDumperTechniqueSet::ShouldDump(XAssetInfo<MaterialTechniqueSet>* asset)
{
return true;
}
void AssetDumperTechniqueSet::DumpAsset(AssetDumpingContext& context, XAssetInfo<MaterialTechniqueSet>* asset)
{
const auto* techset = asset->Asset();
const auto techsetFile = context.OpenAssetFile(GetTechsetFileName(techset));
if (techsetFile)
bool Dumper::ShouldDump(XAssetInfo<MaterialTechniqueSet>* asset)
{
TechsetFileWriter writer(*techsetFile);
writer.DumpTechset(techset);
return true;
}
auto* techniqueState = context.GetZoneAssetDumperState<TechniqueDumpingZoneState>();
for (const auto* technique : techset->techniques)
void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<MaterialTechniqueSet>* asset)
{
if (technique && techniqueState->ShouldDumpTechnique(technique))
const auto* techset = asset->Asset();
const auto techsetFile = context.OpenAssetFile(GetFileNameForTechsetName(techset->name));
if (techsetFile)
{
const auto techniqueFile = context.OpenAssetFile(GetTechniqueFileName(technique));
if (techniqueFile)
TechsetFileWriter writer(*techsetFile);
writer.DumpTechset(techset);
}
auto* techniqueState = context.GetZoneAssetDumperState<TechniqueDumpingZoneState>();
for (const auto* technique : techset->techniques)
{
if (technique && techniqueState->ShouldDumpTechnique(technique))
{
TechniqueFileWriter writer(*techniqueFile);
writer.DumpTechnique(technique);
const auto techniqueFile = context.OpenAssetFile(GetFileNameForTechniqueName(technique->name));
if (techniqueFile)
{
TechniqueFileWriter writer(*techniqueFile);
writer.DumpTechnique(technique);
}
}
}
}
}
} // namespace IW4::techset

View File

@@ -0,0 +1,14 @@
#pragma once
#include "Dumping/AbstractAssetDumper.h"
#include "Game/IW4/IW4.h"
namespace IW4::techset
{
class Dumper final : public AbstractAssetDumper<MaterialTechniqueSet>
{
protected:
bool ShouldDump(XAssetInfo<MaterialTechniqueSet>* asset) override;
void DumpAsset(AssetDumpingContext& context, XAssetInfo<MaterialTechniqueSet>* asset) override;
};
} // namespace IW4::techset

View File

@@ -18,7 +18,7 @@
#include "Sound/AssetDumperSndBank.h"
#include "Sound/AssetDumperSndDriverGlobals.h"
#include "StringTable/StringTableDumperT6.h"
#include "Techset/AssetDumperTechniqueSet.h"
#include "Techset/TechsetDumperT6.h"
#include "Tracer/AssetDumperTracer.h"
#include "Vehicle/AssetDumperVehicle.h"
#include "Weapon/AssetDumperWeapon.h"
@@ -52,7 +52,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
// DUMP_ASSET_POOL(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS)
DUMP_ASSET_POOL(AssetDumperXModel, m_xmodel, ASSET_TYPE_XMODEL)
DUMP_ASSET_POOL(material::JsonDumper, m_material, ASSET_TYPE_MATERIAL)
DUMP_ASSET_POOL(AssetDumperTechniqueSet, m_technique_set, ASSET_TYPE_TECHNIQUE_SET)
DUMP_ASSET_POOL(techset::Dumper, m_technique_set, ASSET_TYPE_TECHNIQUE_SET)
DUMP_ASSET_POOL(image::Dumper, m_image, ASSET_TYPE_IMAGE)
DUMP_ASSET_POOL(AssetDumperSndBank, m_sound_bank, ASSET_TYPE_SOUND)
// DUMP_ASSET_POOL(AssetDumperSndPatch, m_sound_patch, ASSET_TYPE_SOUND_PATCH)

View File

@@ -1,106 +0,0 @@
#include "AssetDumperTechniqueSet.h"
#include <sstream>
#include <unordered_set>
using namespace T6;
class ShaderZoneState final : public IZoneAssetDumperState
{
public:
bool ShouldDumpTechnique(const MaterialTechnique* technique)
{
const auto existingTechnique = m_dumped_techniques.find(technique);
if (existingTechnique == m_dumped_techniques.end())
{
m_dumped_techniques.emplace(technique);
return true;
}
return false;
}
bool ShouldDumpPixelShader(const MaterialPixelShader* pixelShader)
{
const auto existingPixelShader = m_dumped_pixel_shaders.find(pixelShader);
if (existingPixelShader == m_dumped_pixel_shaders.end())
{
m_dumped_pixel_shaders.emplace(pixelShader);
return true;
}
return false;
}
bool ShouldDumpVertexShader(const MaterialVertexShader* vertexShader)
{
const auto existingVertexShader = m_dumped_vertex_shaders.find(vertexShader);
if (existingVertexShader == m_dumped_vertex_shaders.end())
{
m_dumped_vertex_shaders.emplace(vertexShader);
return true;
}
return false;
}
private:
std::unordered_set<const MaterialTechnique*> m_dumped_techniques;
std::unordered_set<const MaterialPixelShader*> m_dumped_pixel_shaders;
std::unordered_set<const MaterialVertexShader*> m_dumped_vertex_shaders;
};
bool AssetDumperTechniqueSet::ShouldDump(XAssetInfo<MaterialTechniqueSet>* asset)
{
return true;
}
void AssetDumperTechniqueSet::DumpPixelShader(const AssetDumpingContext& context, const MaterialPixelShader* pixelShader)
{
std::ostringstream ss;
ss << "shader_bin/ps_" << pixelShader->name << ".cso";
const auto shaderFile = context.OpenAssetFile(ss.str());
if (!shaderFile)
return;
shaderFile->write(pixelShader->prog.loadDef.program, pixelShader->prog.loadDef.programSize);
}
void AssetDumperTechniqueSet::DumpVertexShader(const AssetDumpingContext& context, const MaterialVertexShader* vertexShader)
{
std::ostringstream ss;
ss << "shader_bin/vs_" << vertexShader->name << ".cso";
const auto shaderFile = context.OpenAssetFile(ss.str());
if (!shaderFile)
return;
shaderFile->write(vertexShader->prog.loadDef.program, vertexShader->prog.loadDef.programSize);
}
void AssetDumperTechniqueSet::DumpAsset(AssetDumpingContext& context, XAssetInfo<MaterialTechniqueSet>* asset)
{
const auto* techniqueSet = asset->Asset();
auto* shaderState = context.GetZoneAssetDumperState<ShaderZoneState>();
for (const auto* technique : techniqueSet->techniques)
{
if (!technique || !shaderState->ShouldDumpTechnique(technique))
continue;
for (auto passIndex = 0u; passIndex < technique->passCount; passIndex++)
{
const auto* pixelShader = technique->passArray[passIndex].pixelShader;
if (pixelShader && shaderState->ShouldDumpPixelShader(pixelShader))
DumpPixelShader(context, pixelShader);
const auto* vertexShader = technique->passArray[passIndex].vertexShader;
if (vertexShader && shaderState->ShouldDumpVertexShader(vertexShader))
DumpVertexShader(context, vertexShader);
}
}
}

View File

@@ -1,17 +0,0 @@
#pragma once
#include "Dumping/AbstractAssetDumper.h"
#include "Game/T6/T6.h"
namespace T6
{
class AssetDumperTechniqueSet final : public AbstractAssetDumper<MaterialTechniqueSet>
{
static void DumpPixelShader(const AssetDumpingContext& context, const MaterialPixelShader* pixelShader);
static void DumpVertexShader(const AssetDumpingContext& context, const MaterialVertexShader* vertexShader);
protected:
bool ShouldDump(XAssetInfo<MaterialTechniqueSet>* asset) override;
void DumpAsset(AssetDumpingContext& context, XAssetInfo<MaterialTechniqueSet>* asset) override;
};
} // namespace T6

View File

@@ -0,0 +1,107 @@
#include "TechsetDumperT6.h"
#include "Shader/ShaderCommon.h"
#include <sstream>
#include <unordered_set>
using namespace T6;
namespace
{
class ShaderZoneState final : public IZoneAssetDumperState
{
public:
bool ShouldDumpTechnique(const MaterialTechnique* technique)
{
const auto existingTechnique = m_dumped_techniques.find(technique);
if (existingTechnique == m_dumped_techniques.end())
{
m_dumped_techniques.emplace(technique);
return true;
}
return false;
}
bool ShouldDumpPixelShader(const MaterialPixelShader* pixelShader)
{
const auto existingPixelShader = m_dumped_pixel_shaders.find(pixelShader);
if (existingPixelShader == m_dumped_pixel_shaders.end())
{
m_dumped_pixel_shaders.emplace(pixelShader);
return true;
}
return false;
}
bool ShouldDumpVertexShader(const MaterialVertexShader* vertexShader)
{
const auto existingVertexShader = m_dumped_vertex_shaders.find(vertexShader);
if (existingVertexShader == m_dumped_vertex_shaders.end())
{
m_dumped_vertex_shaders.emplace(vertexShader);
return true;
}
return false;
}
private:
std::unordered_set<const MaterialTechnique*> m_dumped_techniques;
std::unordered_set<const MaterialPixelShader*> m_dumped_pixel_shaders;
std::unordered_set<const MaterialVertexShader*> m_dumped_vertex_shaders;
};
void DumpPixelShader(const AssetDumpingContext& context, const MaterialPixelShader& pixelShader)
{
const auto shaderFile = context.OpenAssetFile(shader::GetFileNameForPixelShaderAssetName(pixelShader.name));
if (!shaderFile)
return;
shaderFile->write(pixelShader.prog.loadDef.program, pixelShader.prog.loadDef.programSize);
}
void DumpVertexShader(const AssetDumpingContext& context, const MaterialVertexShader& vertexShader)
{
const auto shaderFile = context.OpenAssetFile(shader::GetFileNameForVertexShaderAssetName(vertexShader.name));
if (!shaderFile)
return;
shaderFile->write(vertexShader.prog.loadDef.program, vertexShader.prog.loadDef.programSize);
}
} // namespace
namespace T6::techset
{
bool Dumper::ShouldDump(XAssetInfo<MaterialTechniqueSet>* asset)
{
return true;
}
void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<MaterialTechniqueSet>* asset)
{
const auto* techniqueSet = asset->Asset();
auto* shaderState = context.GetZoneAssetDumperState<ShaderZoneState>();
for (const auto* technique : techniqueSet->techniques)
{
if (!technique || !shaderState->ShouldDumpTechnique(technique))
continue;
for (auto passIndex = 0u; passIndex < technique->passCount; passIndex++)
{
const auto* pixelShader = technique->passArray[passIndex].pixelShader;
if (pixelShader && shaderState->ShouldDumpPixelShader(pixelShader))
DumpPixelShader(context, *pixelShader);
const auto* vertexShader = technique->passArray[passIndex].vertexShader;
if (vertexShader && shaderState->ShouldDumpVertexShader(vertexShader))
DumpVertexShader(context, *vertexShader);
}
}
}
} // namespace T6::techset

View File

@@ -0,0 +1,14 @@
#pragma once
#include "Dumping/AbstractAssetDumper.h"
#include "Game/T6/T6.h"
namespace T6::techset
{
class Dumper final : public AbstractAssetDumper<MaterialTechniqueSet>
{
protected:
bool ShouldDump(XAssetInfo<MaterialTechniqueSet>* asset) override;
void DumpAsset(AssetDumpingContext& context, XAssetInfo<MaterialTechniqueSet>* asset) override;
};
} // namespace T6::techset