2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-11-22 21:02:07 +00:00

feat: add vertex declaration to t6 techset dumps

This commit is contained in:
Jan Laupetin
2025-11-15 18:57:39 +00:00
parent 466d7ab0f2
commit b8c37e413d
6 changed files with 309 additions and 60 deletions

View File

@@ -1,7 +1,7 @@
#pragma once #pragma once
#include "Game/T6/CommonT6.h"
#include "Game/T6/T6.h" #include "Game/T6/T6.h"
#include "Techset/CommonTechnique.h"
namespace T6 namespace T6
{ {
@@ -45,57 +45,158 @@ namespace T6
}; };
static_assert(std::extent_v<decltype(techniqueTypeNames)> == TECHNIQUE_COUNT); static_assert(std::extent_v<decltype(techniqueTypeNames)> == TECHNIQUE_COUNT);
static const char* materialStreamDestinationNames[]{ static techset::CommonStreamRoutingSourceInfo streamRoutingSources[]{
"position", "normal", "color[0]", "color[1]", "depth", "texcoord[0]", "texcoord[1]", {
"texcoord[2]", "texcoord[3]", "texcoord[4]", "texcoord[5]", "texcoord[6]", "texcoord[7]", "texcoord[8]", .name = "position",
"texcoord[9]", "texcoord[10]", "texcoord[11]", "texcoord[12]", "texcoord[13]", "blendWeight", .abbreviation = "p",
.optional = false,
},
{
.name = "color",
.abbreviation = "c",
.optional = false,
},
{
.name = "texcoord[0]",
.abbreviation = "t0",
.optional = false,
},
{
.name = "normal",
.abbreviation = "n",
.optional = false,
},
{
.name = "tangent",
.abbreviation = "t",
.optional = false,
},
{
.name = "texcoord[1]",
.abbreviation = "t1",
.optional = false,
},
{
.name = "texcoord[2]",
.abbreviation = "t2",
.optional = true,
},
{
.name = "texcoord[3]",
.abbreviation = "t3",
.optional = true,
},
{
.name = "normalTransform[0]",
.abbreviation = "n0",
.optional = true,
},
{
.name = "normalTransform[1]",
.abbreviation = "n1",
.optional = true,
},
{
.name = "blendWeight",
.abbreviation = "b",
.optional = true,
},
}; };
static_assert(std::extent_v<decltype(materialStreamDestinationNames)> == STREAM_DST_COUNT); static_assert(std::extent_v<decltype(streamRoutingSources)> == STREAM_SRC_COUNT);
static const char* materialStreamDestinationAbbreviation[]{ static techset::CommonStreamRoutingDestinationInfo streamRoutingDestinations[]{
"p", "n", "c0", "c1", "d", "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9", "t10", "t11", "t12", "t13", "b", {
.name = "position",
.abbreviation = "p",
},
{
.name = "normal",
.abbreviation = "n",
},
{
.name = "color[0]",
.abbreviation = "c0",
},
{
.name = "color[1]",
.abbreviation = "c1",
},
{
.name = "depth",
.abbreviation = "d",
},
{
.name = "texcoord[0]",
.abbreviation = "t0",
},
{
.name = "texcoord[1]",
.abbreviation = "t1",
},
{
.name = "texcoord[2]",
.abbreviation = "t2",
},
{
.name = "texcoord[3]",
.abbreviation = "t3",
},
{
.name = "texcoord[4]",
.abbreviation = "t4",
},
{
.name = "texcoord[5]",
.abbreviation = "t5",
},
{
.name = "texcoord[6]",
.abbreviation = "t6",
},
{
.name = "texcoord[7]",
.abbreviation = "t7",
},
{
.name = "texcoord[8]",
.abbreviation = "t8",
},
{
.name = "texcoord[9]",
.abbreviation = "t9",
},
{
.name = "texcoord[10]",
.abbreviation = "t10",
},
{
.name = "texcoord[11]",
.abbreviation = "t11",
},
{
.name = "texcoord[12]",
.abbreviation = "t12",
},
{
.name = "texcoord[13]",
.abbreviation = "t13",
},
{
.name = "blendWeight",
.abbreviation = "b",
},
}; };
static_assert(std::extent_v<decltype(materialStreamDestinationAbbreviation)> == STREAM_DST_COUNT); static_assert(std::extent_v<decltype(streamRoutingDestinations)> == STREAM_DST_COUNT);
static const char* materialStreamSourceNames[]{
"position",
"color",
"texcoord[0]",
"normal",
"tangent",
"texcoord[1]",
"texcoord[2]",
"texcoord[3]",
"normalTransform[0]",
"normalTransform[1]",
"blendWeight",
};
static_assert(std::extent_v<decltype(materialStreamSourceNames)> == STREAM_SRC_COUNT);
static const char* materialStreamSourceAbbreviation[]{
"p",
"c",
"t0",
"n",
"t",
"t1",
"t2",
"t3",
"n0",
"n1",
"b",
};
static_assert(std::extent_v<decltype(materialStreamSourceAbbreviation)> == STREAM_SRC_COUNT);
inline MaterialTypeInfo g_materialTypeInfo[]{ inline MaterialTypeInfo g_materialTypeInfo[]{
{"", "" }, {"", "" },
{"m/", "m_" }, {"m/", "m_" },
{"mc/", "mc_" }, {"mc/", "mc_" },
{"?", "?" }, {"mlv/", "mlv_"},
{"wc/", "wc_" }, {"wc/", "wc_" },
{"?", "?" }, {"wpc/", "wpc_"},
{"?", "?" }, {"wq/", "wq_" },
{"?", "?" }, {"wqc/", "wqc_"},
}; // TODO: Fill this };
static_assert(std::extent_v<decltype(g_materialTypeInfo)> == MTL_TYPE_COUNT); static_assert(std::extent_v<decltype(g_materialTypeInfo)> == MTL_TYPE_COUNT);
} // namespace T6 } // namespace T6

View File

@@ -0,0 +1,55 @@
#include "CommonTechnique.h"
namespace techset
{
CommonStreamRoutingInfos::CommonStreamRoutingInfos(const CommonStreamRoutingSourceInfo* sourceInfos,
const size_t sourceCount,
const CommonStreamRoutingDestinationInfo* destinationNames,
const size_t destinationCount)
: m_sources(sourceCount),
m_destinations(destinationCount)
{
std::copy(sourceInfos, &sourceInfos[sourceCount], m_sources.data());
std::copy(destinationNames, &destinationNames[destinationCount], m_destinations.data());
}
const char* CommonStreamRoutingInfos::GetSourceName(const CommonStreamSource source) const
{
if (source >= m_sources.size())
return nullptr;
return m_sources[source].name;
}
const char* CommonStreamRoutingInfos::GetSourceAbbreviation(const CommonStreamSource source) const
{
if (source >= m_sources.size())
return nullptr;
return m_sources[source].abbreviation;
}
bool CommonStreamRoutingInfos::IsSourceOptional(const CommonStreamSource source) const
{
if (source >= m_sources.size())
return false;
return m_sources[source].optional;
}
const char* CommonStreamRoutingInfos::GetDestinationName(const CommonStreamDestination destination) const
{
if (destination >= m_destinations.size())
return nullptr;
return m_destinations[destination].name;
}
const char* CommonStreamRoutingInfos::GetDestinationAbbreviation(const CommonStreamDestination destination) const
{
if (destination >= m_destinations.size())
return nullptr;
return m_destinations[destination].abbreviation;
}
} // namespace techset

View File

@@ -6,6 +6,54 @@
namespace techset namespace techset
{ {
struct CommonStreamRoutingSourceInfo
{
const char* name;
const char* abbreviation;
bool optional;
};
struct CommonStreamRoutingDestinationInfo
{
const char* name;
const char* abbreviation;
};
typedef std::uint8_t CommonStreamSource;
typedef std::uint8_t CommonStreamDestination;
class CommonStreamRoutingInfos
{
public:
CommonStreamRoutingInfos(const CommonStreamRoutingSourceInfo* sourceInfos,
size_t sourceCount,
const CommonStreamRoutingDestinationInfo* destinationNames,
size_t destinationCount);
[[nodiscard]] const char* GetSourceName(CommonStreamSource source) const;
[[nodiscard]] const char* GetSourceAbbreviation(CommonStreamSource source) const;
[[nodiscard]] bool IsSourceOptional(CommonStreamSource source) const;
[[nodiscard]] const char* GetDestinationName(CommonStreamDestination destination) const;
[[nodiscard]] const char* GetDestinationAbbreviation(CommonStreamDestination destination) const;
private:
std::vector<CommonStreamRoutingSourceInfo> m_sources;
std::vector<CommonStreamRoutingDestinationInfo> m_destinations;
};
class CommonStreamRouting
{
public:
CommonStreamSource m_source;
CommonStreamDestination m_destination;
};
class CommonVertexDeclaration
{
public:
std::vector<CommonStreamRouting> m_routing;
};
class CommonTechniqueShader class CommonTechniqueShader
{ {
public: public:
@@ -27,6 +75,7 @@ namespace techset
DxVersion m_dx_version; DxVersion m_dx_version;
CommonTechniqueShader m_vertex_shader; CommonTechniqueShader m_vertex_shader;
CommonTechniqueShader m_pixel_shader; CommonTechniqueShader m_pixel_shader;
CommonVertexDeclaration m_vertex_declaration;
}; };
class CommonTechnique class CommonTechnique

View File

@@ -99,6 +99,28 @@ namespace
} }
} }
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(techset::CommonStreamRouting{
.m_source = static_cast<techset::CommonStreamSource>(routing.source),
.m_destination = static_cast<techset::CommonStreamDestination>(routing.dest),
});
}
}
return techset::CommonVertexDeclaration{
.m_routing = std::move(commonRouting),
};
}
techset::CommonTechnique ConvertToCommonTechnique(const MaterialTechnique& technique) techset::CommonTechnique ConvertToCommonTechnique(const MaterialTechnique& technique)
{ {
std::vector<techset::CommonPass> passes; std::vector<techset::CommonPass> passes;
@@ -139,6 +161,7 @@ namespace
.m_dx_version = techset::DxVersion::DX11, .m_dx_version = techset::DxVersion::DX11,
.m_vertex_shader = vertexShader, .m_vertex_shader = vertexShader,
.m_pixel_shader = pixelShader, .m_pixel_shader = pixelShader,
.m_vertex_declaration = ConvertToCommonVertexDeclaration(pass.vertexDecl),
}); });
} }
@@ -151,6 +174,9 @@ namespace
void DumpTechniques(AssetDumpingContext& context, const MaterialTechniqueSet& techset) void DumpTechniques(AssetDumpingContext& context, const MaterialTechniqueSet& techset)
{ {
static techset::CommonStreamRoutingInfos routingInfos(
streamRoutingSources, std::extent_v<decltype(streamRoutingSources)>, streamRoutingDestinations, std::extent_v<decltype(streamRoutingDestinations)>);
auto* techniqueState = context.GetZoneAssetDumperState<techset::TechniqueDumpingZoneState>(); auto* techniqueState = context.GetZoneAssetDumperState<techset::TechniqueDumpingZoneState>();
for (const auto* technique : techset.techniques) for (const auto* technique : techset.techniques)
{ {
@@ -158,7 +184,7 @@ namespace
{ {
const auto commonTechnique = ConvertToCommonTechnique(*technique); const auto commonTechnique = ConvertToCommonTechnique(*technique);
techset::DumpCommonTechnique(context, commonTechnique); techset::DumpCommonTechnique(routingInfos, context, commonTechnique);
} }
} }
} }

View File

@@ -21,8 +21,9 @@ namespace
class TechniqueFileWriter : public AbstractTextDumper class TechniqueFileWriter : public AbstractTextDumper
{ {
public: public:
explicit TechniqueFileWriter(std::ostream& stream) TechniqueFileWriter(const CommonStreamRoutingInfos& routingInfos, std::ostream& stream)
: AbstractTextDumper(stream) : AbstractTextDumper(stream),
m_routing_infos(routingInfos)
{ {
} }
@@ -66,9 +67,9 @@ namespace
#endif #endif
DumpStateMap(); DumpStateMap();
DumpShader(pass, pass.m_vertex_shader, TechniqueShaderType::VERTEX_SHADER); DumpShader(pass.m_vertex_shader, TechniqueShaderType::VERTEX_SHADER, pass.m_dx_version);
DumpShader(pass, pass.m_pixel_shader, TechniqueShaderType::PIXEL_SHADER); DumpShader(pass.m_pixel_shader, TechniqueShaderType::PIXEL_SHADER, pass.m_dx_version);
// DumpVertexDecl(pass); DumpVertexDecl(pass.m_vertex_declaration);
DecIndent(); DecIndent();
m_stream << "}\n"; m_stream << "}\n";
@@ -82,7 +83,7 @@ namespace
m_stream << "stateMap \"passthrough\"; // TODO\n"; m_stream << "stateMap \"passthrough\"; // TODO\n";
} }
void DumpShader(const CommonPass& pass, const CommonTechniqueShader& shader, const TechniqueShaderType shaderType) const void DumpShader(const CommonTechniqueShader& shader, const TechniqueShaderType shaderType, const DxVersion dxVersion) const
{ {
if (!shader.m_shader_bin) if (!shader.m_shader_bin)
{ {
@@ -93,7 +94,7 @@ namespace
} }
unsigned versionMajor, versionMinor; unsigned versionMajor, versionMinor;
if (pass.m_dx_version == DxVersion::DX9) if (dxVersion == DxVersion::DX9)
{ {
const auto shaderInfo = d3d9::ShaderAnalyser::GetShaderInfo(shader.m_shader_bin, shader.m_shader_bin_size); const auto shaderInfo = d3d9::ShaderAnalyser::GetShaderInfo(shader.m_shader_bin, shader.m_shader_bin_size);
assert(shaderInfo); assert(shaderInfo);
@@ -105,7 +106,7 @@ namespace
} }
else else
{ {
assert(pass.m_dx_version == DxVersion::DX11); assert(dxVersion == DxVersion::DX11);
const auto shaderInfo = d3d11::ShaderAnalyser::GetShaderInfo(shader.m_shader_bin, shader.m_shader_bin_size); const auto shaderInfo = d3d11::ShaderAnalyser::GetShaderInfo(shader.m_shader_bin, shader.m_shader_bin_size);
assert(shaderInfo); assert(shaderInfo);
if (!shaderInfo) if (!shaderInfo)
@@ -126,17 +127,34 @@ namespace
Indent(); Indent();
m_stream << "}\n"; m_stream << "}\n";
} }
void DumpVertexDecl(const CommonVertexDeclaration& vertexDeclaration) const
{
if (vertexDeclaration.m_routing.empty())
return;
m_stream << "\n";
for (const auto& routing : vertexDeclaration.m_routing)
{
Indent();
m_stream << std::format(
"vertex.{} = code.{};\n", m_routing_infos.GetDestinationName(routing.m_destination), m_routing_infos.GetSourceName(routing.m_source));
}
}
const CommonStreamRoutingInfos& m_routing_infos;
}; };
} // namespace } // namespace
namespace techset namespace techset
{ {
void DumpCommonTechnique(const AssetDumpingContext& context, const CommonTechnique& technique) void DumpCommonTechnique(const CommonStreamRoutingInfos& routingInfos, const AssetDumpingContext& context, const CommonTechnique& technique)
{ {
const auto techniqueFile = context.OpenAssetFile(GetFileNameForTechniqueName(technique.m_name)); const auto techniqueFile = context.OpenAssetFile(GetFileNameForTechniqueName(technique.m_name));
if (techniqueFile) if (techniqueFile)
{ {
TechniqueFileWriter writer(*techniqueFile); TechniqueFileWriter writer(routingInfos, *techniqueFile);
writer.DumpTechnique(technique); writer.DumpTechnique(technique);
} }
} }

View File

@@ -5,5 +5,5 @@
namespace techset namespace techset
{ {
void DumpCommonTechnique(const AssetDumpingContext& context, const CommonTechnique& technique); void DumpCommonTechnique(const CommonStreamRoutingInfos& routingInfos, const AssetDumpingContext& context, const CommonTechnique& technique);
} // namespace techset } // namespace techset