2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-03-15 17:33:03 +00:00

chore: use templated code for t5 techset dumping

This commit is contained in:
Jan Laupetin
2026-03-14 23:22:50 +01:00
parent 1e933d6ae2
commit 04870e8fbf
7 changed files with 74 additions and 302 deletions

View File

@@ -207,6 +207,11 @@ namespace T5
using AssetDDL = Asset<ASSET_TYPE_DDL, ddlRoot_t>;
using AssetGlasses = Asset<ASSET_TYPE_GLASSES, Glasses>;
using AssetEmblemSet = Asset<ASSET_TYPE_EMBLEMSET, EmblemSet>;
using SubAssetTechnique = SubAsset<SUB_ASSET_TYPE_TECHNIQUE, MaterialTechnique>;
using SubAssetVertexDecl = SubAsset<SUB_ASSET_TYPE_VERTEX_DECL, MaterialVertexDeclaration>;
using SubAssetVertexShader = SubAsset<SUB_ASSET_TYPE_VERTEX_SHADER, MaterialVertexShader>;
using SubAssetPixelShader = SubAsset<SUB_ASSET_TYPE_PIXEL_SHADER, MaterialPixelShader>;
} // namespace T5
DEFINE_ASSET_NAME_ACCESSOR(T5::AssetPhysPreset, name);

View File

@@ -1487,6 +1487,16 @@ namespace T5
MaterialArgumentDef u;
};
enum CustomSampler
{
CUSTOM_SAMPLER_REFLECTION_PROBE = 0x0,
CUSTOM_SAMPLER_LIGHTMAP_PRIMARY = 0x1,
CUSTOM_SAMPLER_LIGHTMAP_SECONDARY = 0x2,
CUSTOM_SAMPLER_LIGHTMAP_SECONDARYB = 0x3,
CUSTOM_SAMPLER_COUNT
};
enum MaterialType : unsigned char
{
MTL_TYPE_DEFAULT = 0x0,
@@ -1506,16 +1516,16 @@ namespace T5
enum TechniqueFlags
{
TECHNIQUE_FLAG_1 = 0x1,
TECHNIQUE_FLAG_2 = 0x2,
TECHNIQUE_FLAG_4 = 0x4,
MTL_TECHFLAG_NEEDS_RESOLVED_POST_SUN = 0x1,
MTL_TECHFLAG_NEEDS_RESOLVED_SCENE = 0x2,
MTL_TECHFLAG_ZPREPASS = 0x4,
// Vertex decl has optional source
TECHNIQUE_FLAG_8 = 0x8,
MTL_TECHFLAG_DECL_HAS_OPTIONAL_SOURCE = 0x8,
TECHNIQUE_FLAG_10 = 0x10,
TECHNIQUE_FLAG_20 = 0x20,
TECHNIQUE_FLAG_40 = 0x40,
MTL_TECHFLAG_USES_LIGHT_SPOT_FACTORS = 0x10,
MTL_TECHFLAG_USES_GRASS = 0x20,
MTL_TECHFLAG_USES_FLOATZ = 0x40,
// Any material that has statebits according to any of the following sets this:
// - GFXS1_DEPTHWRITE set

View File

@@ -2,6 +2,7 @@
#include "Game/T5/T5.h"
#include "Techset/CommonTechnique.h"
#include "Techset/CommonTechset.h"
namespace T5
{
@@ -138,6 +139,7 @@ namespace T5
"impact mask",
};
static_assert(std::extent_v<decltype(techniqueTypeNames)> == TECHNIQUE_COUNT);
static inline techset::CommonTechniqueTypeNames commonTechniqueTypeNames(techniqueTypeNames, std::extent_v<decltype(techniqueTypeNames)>);
static techset::CommonStreamRoutingSourceInfo streamRoutingSources[]{
{
@@ -312,6 +314,7 @@ namespace T5
.accessor = "lightSpotFactors",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
.techFlags = MTL_TECHFLAG_USES_LIGHT_SPOT_FACTORS,
},
{
.value = CONST_SRC_CODE_LIGHT_ATTENUATION,
@@ -726,24 +729,28 @@ namespace T5
.accessor = "grassParms",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
.techFlags = MTL_TECHFLAG_USES_GRASS,
},
{
.value = CONST_SRC_CODE_GRASS_FORCE0,
.accessor = "grassForce0",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
.techFlags = MTL_TECHFLAG_USES_GRASS,
},
{
.value = CONST_SRC_CODE_GRASS_FORCE1,
.accessor = "grassForce1",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
.techFlags = MTL_TECHFLAG_USES_GRASS,
},
{
.value = CONST_SRC_CODE_GRASS_WIND_FORCE0,
.accessor = "grassWindForce0",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
.techFlags = MTL_TECHFLAG_USES_GRASS,
},
{
.value = CONST_SRC_CODE_MOTIONBLUR_DIRECTION_AND_MAGNITUDE,
@@ -834,6 +841,7 @@ namespace T5
.accessor = "destructibleParms",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
.techFlags = TECHNIQUE_FLAG_200,
},
{
.value = CONST_SRC_CODE_CLOUD_WORLD_AREA,
@@ -858,6 +866,7 @@ namespace T5
.accessor = "__characterCharredAmount",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
.techFlags = TECHNIQUE_FLAG_200,
},
{
.value = CONST_SRC_CODE_TREECANOPY_PARMS,
@@ -1332,192 +1341,224 @@ namespace T5
.accessor = "worldMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM,
.transposedMatrix = CONST_SRC_CODE_TRANSPOSE_WORLD_MATRIX,
},
{
.value = CONST_SRC_CODE_INVERSE_WORLD_MATRIX,
.accessor = "inverseWorldMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM,
.transposedMatrix = CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_MATRIX,
},
{
.value = CONST_SRC_CODE_TRANSPOSE_WORLD_MATRIX,
.accessor = "transposeWorldMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM,
.transposedMatrix = CONST_SRC_CODE_WORLD_MATRIX,
},
{
.value = CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_MATRIX,
.accessor = "inverseTransposeWorldMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM,
.transposedMatrix = CONST_SRC_CODE_INVERSE_WORLD_MATRIX,
},
{
.value = CONST_SRC_CODE_VIEW_MATRIX,
.accessor = "viewMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT,
.transposedMatrix = CONST_SRC_CODE_TRANSPOSE_VIEW_MATRIX,
},
{
.value = CONST_SRC_CODE_INVERSE_VIEW_MATRIX,
.accessor = "inverseViewMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT,
.transposedMatrix = CONST_SRC_CODE_INVERSE_TRANSPOSE_VIEW_MATRIX,
},
{
.value = CONST_SRC_CODE_TRANSPOSE_VIEW_MATRIX,
.accessor = "transposeViewMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT,
.transposedMatrix = CONST_SRC_CODE_VIEW_MATRIX,
},
{
.value = CONST_SRC_CODE_INVERSE_TRANSPOSE_VIEW_MATRIX,
.accessor = "inverseTransposeViewMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT,
.transposedMatrix = CONST_SRC_CODE_INVERSE_VIEW_MATRIX,
},
{
.value = CONST_SRC_CODE_PROJECTION_MATRIX,
.accessor = "projectionMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT,
.transposedMatrix = CONST_SRC_CODE_TRANSPOSE_PROJECTION_MATRIX,
},
{
.value = CONST_SRC_CODE_INVERSE_PROJECTION_MATRIX,
.accessor = "inverseProjectionMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT,
.transposedMatrix = CONST_SRC_CODE_INVERSE_TRANSPOSE_PROJECTION_MATRIX,
},
{
.value = CONST_SRC_CODE_TRANSPOSE_PROJECTION_MATRIX,
.accessor = "transposeProjectionMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT,
.transposedMatrix = CONST_SRC_CODE_PROJECTION_MATRIX,
},
{
.value = CONST_SRC_CODE_INVERSE_TRANSPOSE_PROJECTION_MATRIX,
.accessor = "inverseTransposeProjectionMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT,
.transposedMatrix = CONST_SRC_CODE_INVERSE_PROJECTION_MATRIX,
},
{
.value = CONST_SRC_CODE_WORLD_VIEW_MATRIX,
.accessor = "worldViewMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM,
.transposedMatrix = CONST_SRC_CODE_TRANSPOSE_WORLD_VIEW_MATRIX,
},
{
.value = CONST_SRC_CODE_INVERSE_WORLD_VIEW_MATRIX,
.accessor = "inverseWorldViewMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM,
.transposedMatrix = CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_VIEW_MATRIX,
},
{
.value = CONST_SRC_CODE_TRANSPOSE_WORLD_VIEW_MATRIX,
.accessor = "transposeWorldViewMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM,
.transposedMatrix = CONST_SRC_CODE_WORLD_VIEW_MATRIX,
},
{
.value = CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_VIEW_MATRIX,
.accessor = "inverseTransposeWorldViewMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM,
.transposedMatrix = CONST_SRC_CODE_INVERSE_WORLD_VIEW_MATRIX,
},
{
.value = CONST_SRC_CODE_VIEW_PROJECTION_MATRIX,
.accessor = "viewProjectionMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT,
.transposedMatrix = CONST_SRC_CODE_TRANSPOSE_VIEW_PROJECTION_MATRIX,
},
{
.value = CONST_SRC_CODE_INVERSE_VIEW_PROJECTION_MATRIX,
.accessor = "inverseViewProjectionMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT,
.transposedMatrix = CONST_SRC_CODE_INVERSE_TRANSPOSE_VIEW_PROJECTION_MATRIX,
},
{
.value = CONST_SRC_CODE_TRANSPOSE_VIEW_PROJECTION_MATRIX,
.accessor = "transposeViewProjectionMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT,
.transposedMatrix = CONST_SRC_CODE_VIEW_PROJECTION_MATRIX,
},
{
.value = CONST_SRC_CODE_INVERSE_TRANSPOSE_VIEW_PROJECTION_MATRIX,
.accessor = "inverseTransposeViewProjectionMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT,
.transposedMatrix = CONST_SRC_CODE_INVERSE_VIEW_PROJECTION_MATRIX,
},
{
.value = CONST_SRC_CODE_WORLD_VIEW_PROJECTION_MATRIX,
.accessor = "worldViewProjectionMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM,
.transposedMatrix = CONST_SRC_CODE_TRANSPOSE_WORLD_VIEW_PROJECTION_MATRIX,
},
{
.value = CONST_SRC_CODE_INVERSE_WORLD_VIEW_PROJECTION_MATRIX,
.accessor = "inverseWorldViewProjectionMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM,
.transposedMatrix = CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_VIEW_PROJECTION_MATRIX,
},
{
.value = CONST_SRC_CODE_TRANSPOSE_WORLD_VIEW_PROJECTION_MATRIX,
.accessor = "transposeWorldViewProjectionMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM,
.transposedMatrix = CONST_SRC_CODE_WORLD_VIEW_PROJECTION_MATRIX,
},
{
.value = CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_VIEW_PROJECTION_MATRIX,
.accessor = "inverseTransposeWorldViewProjectionMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM,
.transposedMatrix = CONST_SRC_CODE_INVERSE_WORLD_VIEW_PROJECTION_MATRIX,
},
{
.value = CONST_SRC_CODE_SHADOW_LOOKUP_MATRIX,
.accessor = "shadowLookupMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT,
.transposedMatrix = CONST_SRC_CODE_TRANSPOSE_SHADOW_LOOKUP_MATRIX,
},
{
.value = CONST_SRC_CODE_INVERSE_SHADOW_LOOKUP_MATRIX,
.accessor = "inverseShadowLookupMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT,
.transposedMatrix = CONST_SRC_CODE_INVERSE_TRANSPOSE_SHADOW_LOOKUP_MATRIX,
},
{
.value = CONST_SRC_CODE_TRANSPOSE_SHADOW_LOOKUP_MATRIX,
.accessor = "transposeShadowLookupMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT,
.transposedMatrix = CONST_SRC_CODE_SHADOW_LOOKUP_MATRIX,
},
{
.value = CONST_SRC_CODE_INVERSE_TRANSPOSE_SHADOW_LOOKUP_MATRIX,
.accessor = "inverseTransposeShadowLookupMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT,
.transposedMatrix = CONST_SRC_CODE_INVERSE_SHADOW_LOOKUP_MATRIX,
},
{
.value = CONST_SRC_CODE_WORLD_OUTDOOR_LOOKUP_MATRIX,
.accessor = "worldOutdoorLookupMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM,
.transposedMatrix = CONST_SRC_CODE_TRANSPOSE_WORLD_OUTDOOR_LOOKUP_MATRIX,
},
{
.value = CONST_SRC_CODE_INVERSE_WORLD_OUTDOOR_LOOKUP_MATRIX,
.accessor = "inverseWorldOutdoorLookupMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM,
.transposedMatrix = CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_OUTDOOR_LOOKUP_MATRIX,
},
{
.value = CONST_SRC_CODE_TRANSPOSE_WORLD_OUTDOOR_LOOKUP_MATRIX,
.accessor = "transposeWorldOutdoorLookupMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM,
.transposedMatrix = CONST_SRC_CODE_WORLD_OUTDOOR_LOOKUP_MATRIX,
},
{
.value = CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_OUTDOOR_LOOKUP_MATRIX,
.accessor = "inverseTransposeWorldOutdoorLookupMatrix",
.arrayCount = 0,
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM,
.transposedMatrix = CONST_SRC_CODE_INVERSE_WORLD_OUTDOOR_LOOKUP_MATRIX,
},
};
@@ -1546,11 +1587,13 @@ namespace T5
.value = TEXTURE_SRC_CODE_LIGHTMAP_PRIMARY,
.accessor = "lightmapSamplerPrimary",
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM,
.customSamplerIndex = CUSTOM_SAMPLER_LIGHTMAP_SECONDARY,
},
{
.value = TEXTURE_SRC_CODE_LIGHTMAP_SECONDARY,
.accessor = "lightmapSamplerSecondary",
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM,
.customSamplerIndex = CUSTOM_SAMPLER_LIGHTMAP_SECONDARY,
},
{
.value = TEXTURE_SRC_CODE_SHADOWMAP_SUN,
@@ -1571,11 +1614,13 @@ namespace T5
.value = TEXTURE_SRC_CODE_RESOLVED_POST_SUN,
.accessor = "resolvedPostSun",
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
.techFlags = MTL_TECHFLAG_NEEDS_RESOLVED_POST_SUN,
},
{
.value = TEXTURE_SRC_CODE_RESOLVED_SCENE,
.accessor = "resolvedScene",
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
.techFlags = MTL_TECHFLAG_NEEDS_RESOLVED_SCENE,
},
{
.value = TEXTURE_SRC_CODE_POST_EFFECT_SRC,
@@ -1621,16 +1666,19 @@ namespace T5
.value = TEXTURE_SRC_CODE_FLOATZ,
.accessor = "floatZSampler",
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
.techFlags = MTL_TECHFLAG_USES_FLOATZ,
},
{
.value = TEXTURE_SRC_CODE_PROCESSED_FLOATZ,
.accessor = "processedFloatZSampler",
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
.techFlags = MTL_TECHFLAG_USES_FLOATZ,
},
{
.value = TEXTURE_SRC_CODE_RAW_FLOATZ,
.accessor = "rawFloatZSampler",
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
.techFlags = MTL_TECHFLAG_USES_FLOATZ,
},
{
.value = TEXTURE_SRC_CODE_CASE_TEXTURE,
@@ -1691,6 +1739,7 @@ namespace T5
.value = TEXTURE_SRC_CODE_LIGHTMAP_SECONDARYB,
.accessor = "lightmapSamplerSecondaryB",
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM,
.customSamplerIndex = CUSTOM_SAMPLER_LIGHTMAP_SECONDARYB,
},
{
.value = TEXTURE_SRC_CODE_TEXTURE_0,

View File

@@ -1,272 +0,0 @@
#include "TechsetDumperT5.h"
#include "Game/T5/Material/MaterialConstantZoneStateT5.h"
#include "Game/T5/Techset/TechsetConstantsT5.h"
#include "Shader/ShaderCommon.h"
#include "Techset/CommonTechniqueDumper.h"
#include "Techset/CommonTechsetDumper.h"
#include "Techset/ShaderDumpingZoneState.h"
#include "Techset/TechniqueDumpingZoneState.h"
#include <cstdint>
using namespace T5;
namespace
{
void DumpPixelShader(const AssetDumpingContext& context, const MaterialPixelShader& pixelShader)
{
const auto shaderFile = context.OpenAssetFile(shader::GetFileNameForPixelShaderAssetName(pixelShader.name));
if (!shaderFile)
return;
shaderFile->write(reinterpret_cast<char*>(pixelShader.prog.loadDef.program), pixelShader.prog.loadDef.programSize * sizeof(uint32_t));
}
void DumpVertexShader(const AssetDumpingContext& context, const MaterialVertexShader& vertexShader)
{
const auto shaderFile = context.OpenAssetFile(shader::GetFileNameForVertexShaderAssetName(vertexShader.name));
if (!shaderFile)
return;
shaderFile->write(reinterpret_cast<char*>(vertexShader.prog.loadDef.program), vertexShader.prog.loadDef.programSize * sizeof(uint32_t));
}
void DumpShaders(AssetDumpingContext& context, const MaterialTechniqueSet& techset)
{
auto* shaderState = context.GetZoneAssetDumperState<techset::ShaderDumpingZoneState>();
for (const auto* technique : techset.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);
}
}
}
techset::CommonVertexDeclaration ConvertToCommonVertexDeclaration(const MaterialVertexDeclaration* vertexDecl)
{
std::vector<techset::CommonStreamRouting> commonRouting;
if (vertexDecl)
{
const auto streamCount = std::min(static_cast<size_t>(vertexDecl->streamCount), std::extent_v<decltype(MaterialVertexStreamRouting::data)>);
for (auto streamIndex = 0u; streamIndex < streamCount; streamIndex++)
{
const auto& routing = vertexDecl->routing.data[streamIndex];
commonRouting.emplace_back(static_cast<techset::CommonStreamSource>(routing.source),
static_cast<techset::CommonStreamDestination>(routing.dest));
}
}
return techset::CommonVertexDeclaration(std::move(commonRouting));
}
techset::CommonShaderArg ConvertToCommonArg(const MaterialShaderArgument& arg)
{
const techset::CommonShaderArgDestination destination{.dx9 = {.m_destination_register = arg.dest}};
switch (arg.type)
{
case MTL_ARG_CODE_VERTEX_CONST:
case MTL_ARG_CODE_PIXEL_CONST:
{
const techset::CommonShaderArgCodeConstValue codeConstValue{
.m_index = static_cast<techset::CommonCodeConstSource>(arg.u.codeConst.index),
.m_first_row = arg.u.codeConst.firstRow,
.m_row_count = arg.u.codeConst.rowCount,
};
const techset::CommonShaderArgValue value{.code_const_source = codeConstValue};
return techset::CommonShaderArg(commonArgumentTypes[arg.type], destination, value);
}
case MTL_ARG_MATERIAL_VERTEX_CONST:
case MTL_ARG_MATERIAL_PIXEL_CONST:
{
const techset::CommonShaderArgValue value{
.name_hash = arg.u.nameHash,
};
return techset::CommonShaderArg(commonArgumentTypes[arg.type], destination, value);
}
case MTL_ARG_CODE_PIXEL_SAMPLER:
{
const techset::CommonShaderArgValue value{
.code_sampler_source = static_cast<techset::CommonCodeSamplerSource>(arg.u.codeSampler),
};
return techset::CommonShaderArg(commonArgumentTypes[arg.type], destination, value);
}
case MTL_ARG_MATERIAL_PIXEL_SAMPLER:
{
const techset::CommonShaderArgValue value{
.name_hash = arg.u.nameHash,
};
return techset::CommonShaderArg(commonArgumentTypes[arg.type], destination, value);
}
default:
case MTL_ARG_LITERAL_VERTEX_CONST:
case MTL_ARG_LITERAL_PIXEL_CONST:
{
techset::CommonShaderArgValue value{};
if (arg.u.literalConst)
{
value.literal_value = {
(*arg.u.literalConst)[0],
(*arg.u.literalConst)[1],
(*arg.u.literalConst)[2],
(*arg.u.literalConst)[3],
};
}
return techset::CommonShaderArg(commonArgumentTypes[arg.type], destination, value);
}
}
}
techset::CommonTechniqueShader ConvertToCommonShader(const MaterialVertexShader* vertexShader)
{
techset::CommonTechniqueShader result{};
if (!vertexShader)
return result;
if (vertexShader->name)
result.m_name = vertexShader->name;
if (vertexShader->prog.loadDef.program)
{
result.m_bin = techset::CommonTechniqueShaderBin{
.m_shader_bin = vertexShader->prog.loadDef.program,
.m_shader_bin_size = vertexShader->prog.loadDef.programSize * sizeof(uint32_t),
};
}
return result;
}
techset::CommonTechniqueShader ConvertToCommonShader(const MaterialPixelShader* pixelShader)
{
techset::CommonTechniqueShader result{};
if (!pixelShader)
return result;
if (pixelShader->name)
result.m_name = pixelShader->name;
if (pixelShader->prog.loadDef.program)
{
result.m_bin = techset::CommonTechniqueShaderBin{
.m_shader_bin = pixelShader->prog.loadDef.program,
.m_shader_bin_size = pixelShader->prog.loadDef.programSize * sizeof(uint32_t),
};
}
return result;
}
techset::CommonTechnique ConvertToCommonTechnique(const MaterialTechnique& technique)
{
techset::CommonTechnique commonTechnique(technique.name ? technique.name : std::string(), technique.flags);
for (auto passIndex = 0u; passIndex < technique.passCount; passIndex++)
{
const auto& pass = technique.passArray[passIndex];
techset::CommonPass commonPass(pass.customSamplerFlags,
// No clue what the actual state map was
"passthrough",
ConvertToCommonShader(pass.vertexShader),
ConvertToCommonShader(pass.pixelShader),
ConvertToCommonVertexDeclaration(pass.vertexDecl),
std::string());
if (pass.args)
{
const size_t totalArgCount = pass.perPrimArgCount + pass.perObjArgCount + pass.stableArgCount;
commonPass.m_args.reserve(totalArgCount);
for (auto argIndex = 0uz; argIndex < totalArgCount; argIndex++)
commonPass.m_args.emplace_back(ConvertToCommonArg(pass.args[argIndex]));
}
commonTechnique.m_passes.emplace_back(std::move(commonPass));
}
return commonTechnique;
}
void DumpTechniques(AssetDumpingContext& context, const MaterialTechniqueSet& techset, const bool debug)
{
auto* techniqueState = context.GetZoneAssetDumperState<techset::TechniqueDumpingZoneState>();
const auto* materialConstantState = context.GetZoneAssetDumperState<MaterialConstantZoneState>();
for (const auto* technique : techset.techniques)
{
if (technique && techniqueState->ShouldDumpTechnique(technique))
{
const auto commonTechnique = ConvertToCommonTechnique(*technique);
techset::DumpCommonTechnique(
context, commonTechnique, techset::DxVersion::DX9, commonCodeSourceInfos, commonRoutingInfos, *materialConstantState, debug);
}
}
}
techset::CommonTechset ConvertToCommonTechset(const MaterialTechniqueSet& techset)
{
std::vector<std::string> techniqueNames(std::extent_v<decltype(techniqueTypeNames)>);
for (auto techniqueIndex = 0u; techniqueIndex < std::extent_v<decltype(techniqueTypeNames)>; techniqueIndex++)
{
const auto* technique = techset.techniques[techniqueIndex];
if (technique && technique->name)
techniqueNames[techniqueIndex] = technique->name;
}
return techset::CommonTechset(techset.name, std::move(techniqueNames));
}
void DumpTechset(const AssetDumpingContext& context, const MaterialTechniqueSet& techset)
{
static techset::CommonTechniqueTypeNames commonNames(techniqueTypeNames, std::extent_v<decltype(techniqueTypeNames)>);
const auto commonTechset = ConvertToCommonTechset(techset);
techset::DumpCommonTechset(commonNames, context, commonTechset);
}
} // namespace
namespace techset
{
DumperT5::DumperT5(const bool debug)
: m_debug(debug)
{
}
void DumperT5::Dump(AssetDumpingContext& context)
{
context.GetZoneAssetDumperState<MaterialConstantZoneState>()->EnsureInitialized();
AbstractAssetDumper::Dump(context);
}
void DumperT5::DumpAsset(AssetDumpingContext& context, const XAssetInfo<AssetTechniqueSet::Type>& asset)
{
const auto* techniqueSet = asset.Asset();
DumpTechset(context, *techniqueSet);
DumpTechniques(context, *techniqueSet, m_debug);
DumpShaders(context, *techniqueSet);
}
} // namespace techset

View File

@@ -1,21 +0,0 @@
#pragma once
#include "Dumping/AbstractAssetDumper.h"
#include "Game/T5/T5.h"
namespace techset
{
class DumperT5 final : public AbstractAssetDumper<T5::AssetTechniqueSet>
{
public:
explicit DumperT5(bool debug);
void Dump(AssetDumpingContext& context) override;
protected:
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<T5::AssetTechniqueSet::Type>& asset) override;
private:
bool m_debug;
};
} // namespace techset

View File

@@ -1,4 +1,4 @@
#options GAME(IW3, IW4, T6)
#options GAME(IW3, IW4, T5, T6)
#filename "Game/" + GAME + "/Techset/TechsetDumper" + GAME + ".cpp"
@@ -19,6 +19,7 @@
#elif GAME == "T5"
#define FEATURE_T5
#define IS_DX9
#define DUMP_SHADERS "1"
#elif GAME == "T6"
#define FEATURE_T6
#define IS_DX11

View File

@@ -1,4 +1,4 @@
#options GAME(IW3, IW4, T6)
#options GAME(IW3, IW4, T5, T6)
#filename "Game/" + GAME + "/Techset/TechsetDumper" + GAME + ".h"