mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-05-25 02:51:43 +00:00
fix: errors with common techset dumping
* not respecting transposing matrices * not respecting arrays
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
#include "Techset/TechniqueDumpingZoneState.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <unordered_set>
|
||||
|
||||
using namespace T5;
|
||||
|
||||
@@ -67,10 +66,8 @@ namespace
|
||||
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),
|
||||
});
|
||||
commonRouting.emplace_back(static_cast<techset::CommonStreamSource>(routing.source),
|
||||
static_cast<techset::CommonStreamDestination>(routing.dest));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,92 +76,72 @@ namespace
|
||||
|
||||
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:
|
||||
return techset::CommonShaderArg{
|
||||
.m_type = techset::CommonShaderArgType::CODE_CONST,
|
||||
.m_destination = {.dx9 =
|
||||
{
|
||||
.m_destination_register = arg.dest,
|
||||
}},
|
||||
.m_value = {
|
||||
.code_const_source = static_cast<techset::CommonCodeConstSource>(arg.u.codeConst.index),
|
||||
}
|
||||
{
|
||||
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:
|
||||
return techset::CommonShaderArg{
|
||||
.m_type = techset::CommonShaderArgType::MATERIAL_CONST,
|
||||
.m_destination = {.dx9 =
|
||||
{
|
||||
.m_destination_register = arg.dest,
|
||||
}},
|
||||
.m_value = {
|
||||
.name_hash = arg.u.nameHash,
|
||||
}
|
||||
{
|
||||
const techset::CommonShaderArgValue value{
|
||||
.name_hash = arg.u.nameHash,
|
||||
};
|
||||
|
||||
return techset::CommonShaderArg(commonArgumentTypes[arg.type], destination, value);
|
||||
}
|
||||
|
||||
case MTL_ARG_CODE_PIXEL_SAMPLER:
|
||||
return techset::CommonShaderArg{
|
||||
.m_type = techset::CommonShaderArgType::CODE_SAMPLER,
|
||||
.m_destination = {.dx9 =
|
||||
{
|
||||
.m_destination_register = arg.dest,
|
||||
}},
|
||||
.m_value = {
|
||||
.code_sampler_source = static_cast<techset::CommonCodeSamplerSource>(arg.u.codeSampler),
|
||||
}
|
||||
{
|
||||
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:
|
||||
return techset::CommonShaderArg{
|
||||
.m_type = techset::CommonShaderArgType::MATERIAL_SAMPLER,
|
||||
.m_destination = {.dx9 =
|
||||
{
|
||||
.m_destination_register = arg.dest,
|
||||
}},
|
||||
.m_value = {
|
||||
.name_hash = arg.u.nameHash,
|
||||
}
|
||||
{
|
||||
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)
|
||||
{
|
||||
return techset::CommonShaderArg{
|
||||
.m_type = techset::CommonShaderArgType::LITERAL_CONST,
|
||||
.m_destination = {.dx9 =
|
||||
{
|
||||
.m_destination_register = arg.dest,
|
||||
}},
|
||||
.m_value = {
|
||||
.literal_value =
|
||||
{
|
||||
(*arg.u.literalConst)[0],
|
||||
(*arg.u.literalConst)[1],
|
||||
(*arg.u.literalConst)[2],
|
||||
(*arg.u.literalConst)[3],
|
||||
}, }
|
||||
value.literal_value = {
|
||||
(*arg.u.literalConst)[0],
|
||||
(*arg.u.literalConst)[1],
|
||||
(*arg.u.literalConst)[2],
|
||||
(*arg.u.literalConst)[3],
|
||||
};
|
||||
}
|
||||
|
||||
return techset::CommonShaderArg{
|
||||
.m_type = techset::CommonShaderArgType::LITERAL_CONST,
|
||||
.m_destination = {.dx9 =
|
||||
{
|
||||
.m_destination_register = arg.dest,
|
||||
}},
|
||||
.m_value = {},
|
||||
};
|
||||
return techset::CommonShaderArg(commonArgumentTypes[arg.type], destination, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
techset::CommonTechniqueShader ConvertToCommonShader(const MaterialPass& pass, const MaterialVertexShader* vertexShader)
|
||||
techset::CommonTechniqueShader ConvertToCommonShader(const MaterialVertexShader* vertexShader)
|
||||
{
|
||||
techset::CommonTechniqueShader result{};
|
||||
if (!vertexShader)
|
||||
@@ -175,34 +152,16 @@ namespace
|
||||
|
||||
if (vertexShader->prog.loadDef.program)
|
||||
{
|
||||
result.m_shader_bin = vertexShader->prog.loadDef.program;
|
||||
result.m_shader_bin_size = vertexShader->prog.loadDef.programSize * sizeof(uint32_t);
|
||||
}
|
||||
|
||||
if (pass.args)
|
||||
{
|
||||
const size_t totalArgCount = pass.perPrimArgCount + pass.perObjArgCount + pass.stableArgCount;
|
||||
for (auto argIndex = 0uz; argIndex < totalArgCount; argIndex++)
|
||||
{
|
||||
const auto& arg = pass.args[argIndex];
|
||||
|
||||
switch (arg.type)
|
||||
{
|
||||
case MTL_ARG_CODE_VERTEX_CONST:
|
||||
case MTL_ARG_MATERIAL_VERTEX_CONST:
|
||||
case MTL_ARG_LITERAL_VERTEX_CONST:
|
||||
result.m_args.emplace_back(ConvertToCommonArg(arg));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
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 MaterialPass& pass, const MaterialPixelShader* pixelShader)
|
||||
techset::CommonTechniqueShader ConvertToCommonShader(const MaterialPixelShader* pixelShader)
|
||||
{
|
||||
techset::CommonTechniqueShader result{};
|
||||
if (!pixelShader)
|
||||
@@ -213,30 +172,10 @@ namespace
|
||||
|
||||
if (pixelShader->prog.loadDef.program)
|
||||
{
|
||||
result.m_shader_bin = pixelShader->prog.loadDef.program;
|
||||
result.m_shader_bin_size = pixelShader->prog.loadDef.programSize * sizeof(uint32_t);
|
||||
}
|
||||
|
||||
if (pass.args)
|
||||
{
|
||||
const size_t totalArgCount = pass.perPrimArgCount + pass.perObjArgCount + pass.stableArgCount;
|
||||
for (auto argIndex = 0uz; argIndex < totalArgCount; argIndex++)
|
||||
{
|
||||
const auto& arg = pass.args[argIndex];
|
||||
|
||||
switch (arg.type)
|
||||
{
|
||||
case MTL_ARG_CODE_PIXEL_CONST:
|
||||
case MTL_ARG_CODE_PIXEL_SAMPLER:
|
||||
case MTL_ARG_MATERIAL_PIXEL_CONST:
|
||||
case MTL_ARG_MATERIAL_PIXEL_SAMPLER:
|
||||
case MTL_ARG_LITERAL_PIXEL_CONST:
|
||||
result.m_args.emplace_back(ConvertToCommonArg(arg));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
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;
|
||||
@@ -244,26 +183,30 @@ namespace
|
||||
|
||||
techset::CommonTechnique ConvertToCommonTechnique(const MaterialTechnique& technique)
|
||||
{
|
||||
std::vector<techset::CommonPass> passes;
|
||||
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));
|
||||
|
||||
passes.emplace_back(techset::CommonPass{
|
||||
.m_sampler_flags = pass.customSamplerFlags,
|
||||
.m_dx_version = techset::DxVersion::DX9,
|
||||
.m_vertex_shader = ConvertToCommonShader(pass, pass.vertexShader),
|
||||
.m_pixel_shader = ConvertToCommonShader(pass, pass.pixelShader),
|
||||
.m_vertex_declaration = ConvertToCommonVertexDeclaration(pass.vertexDecl),
|
||||
});
|
||||
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 techset::CommonTechnique{
|
||||
.m_name = technique.name ? technique.name : std::string(),
|
||||
.m_flags = technique.flags,
|
||||
.m_passes = std::move(passes),
|
||||
};
|
||||
return commonTechnique;
|
||||
}
|
||||
|
||||
void DumpTechniques(AssetDumpingContext& context, const MaterialTechniqueSet& techset)
|
||||
@@ -276,7 +219,8 @@ namespace
|
||||
{
|
||||
const auto commonTechnique = ConvertToCommonTechnique(*technique);
|
||||
|
||||
techset::DumpCommonTechnique(context, commonTechnique, commonCodeSourceInfos, commonRoutingInfos, *materialConstantState);
|
||||
techset::DumpCommonTechnique(
|
||||
context, commonTechnique, techset::DxVersion::DX9, commonCodeSourceInfos, commonRoutingInfos, *materialConstantState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user