2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-11-29 07:47:48 +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

@@ -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)
{
std::vector<techset::CommonPass> passes;
@@ -139,6 +161,7 @@ namespace
.m_dx_version = techset::DxVersion::DX11,
.m_vertex_shader = vertexShader,
.m_pixel_shader = pixelShader,
.m_vertex_declaration = ConvertToCommonVertexDeclaration(pass.vertexDecl),
});
}
@@ -151,6 +174,9 @@ namespace
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>();
for (const auto* technique : techset.techniques)
{
@@ -158,7 +184,7 @@ namespace
{
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
{
public:
explicit TechniqueFileWriter(std::ostream& stream)
: AbstractTextDumper(stream)
TechniqueFileWriter(const CommonStreamRoutingInfos& routingInfos, std::ostream& stream)
: AbstractTextDumper(stream),
m_routing_infos(routingInfos)
{
}
@@ -66,9 +67,9 @@ namespace
#endif
DumpStateMap();
DumpShader(pass, pass.m_vertex_shader, TechniqueShaderType::VERTEX_SHADER);
DumpShader(pass, pass.m_pixel_shader, TechniqueShaderType::PIXEL_SHADER);
// DumpVertexDecl(pass);
DumpShader(pass.m_vertex_shader, TechniqueShaderType::VERTEX_SHADER, pass.m_dx_version);
DumpShader(pass.m_pixel_shader, TechniqueShaderType::PIXEL_SHADER, pass.m_dx_version);
DumpVertexDecl(pass.m_vertex_declaration);
DecIndent();
m_stream << "}\n";
@@ -82,7 +83,7 @@ namespace
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)
{
@@ -93,7 +94,7 @@ namespace
}
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);
assert(shaderInfo);
@@ -105,7 +106,7 @@ namespace
}
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);
assert(shaderInfo);
if (!shaderInfo)
@@ -126,17 +127,34 @@ namespace
Indent();
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 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));
if (techniqueFile)
{
TechniqueFileWriter writer(*techniqueFile);
TechniqueFileWriter writer(routingInfos, *techniqueFile);
writer.DumpTechnique(technique);
}
}

View File

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