mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-03-05 20:43:03 +00:00
fix: errors with common techset dumping
* not respecting transposing matrices * not respecting arrays
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
#include "Techset/ShaderDumpingZoneState.h"
|
||||
#include "Techset/TechniqueDumpingZoneState.h"
|
||||
|
||||
#include <unordered_set>
|
||||
#include <cassert>
|
||||
|
||||
using namespace T6;
|
||||
|
||||
@@ -66,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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,100 +80,119 @@ namespace
|
||||
{
|
||||
case MTL_ARG_CODE_VERTEX_CONST:
|
||||
case MTL_ARG_CODE_PIXEL_CONST:
|
||||
return techset::CommonShaderArg{
|
||||
.m_type = techset::CommonShaderArgType::CODE_CONST,
|
||||
.m_destination = {.dx11 =
|
||||
{
|
||||
.m_location = arg.location.offset,
|
||||
.m_size = arg.size,
|
||||
.m_buffer = arg.buffer,
|
||||
}},
|
||||
.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};
|
||||
const techset::CommonShaderArgLocationDx11 location{
|
||||
.constant_buffer_offset = arg.location.offset,
|
||||
};
|
||||
const techset::CommonShaderArgDestination destination = {
|
||||
.dx11 = {
|
||||
.m_location = location,
|
||||
.m_size = arg.size,
|
||||
.m_buffer = arg.buffer,
|
||||
}
|
||||
};
|
||||
|
||||
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 = {.dx11 =
|
||||
{
|
||||
.m_location = arg.location.offset,
|
||||
.m_size = arg.size,
|
||||
.m_buffer = arg.buffer,
|
||||
}},
|
||||
.m_value = {
|
||||
.name_hash = arg.u.nameHash,
|
||||
}
|
||||
{
|
||||
const techset::CommonShaderArgValue value{
|
||||
.name_hash = arg.u.nameHash,
|
||||
};
|
||||
const techset::CommonShaderArgLocationDx11 location{
|
||||
.constant_buffer_offset = arg.location.offset,
|
||||
};
|
||||
const techset::CommonShaderArgDestination destination{
|
||||
.dx11 = {
|
||||
.m_location = location,
|
||||
.m_size = arg.size,
|
||||
.m_buffer = arg.buffer,
|
||||
}
|
||||
};
|
||||
|
||||
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 = {.dx11 =
|
||||
{
|
||||
.m_location = arg.location.samplerIndex,
|
||||
.m_size = arg.size,
|
||||
.m_buffer = arg.buffer,
|
||||
}},
|
||||
.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),
|
||||
};
|
||||
const techset::CommonShaderArgLocationDx11 location{
|
||||
.texture_index = arg.location.textureIndex,
|
||||
.sampler_index = arg.location.samplerIndex,
|
||||
};
|
||||
const techset::CommonShaderArgDestination destination = {
|
||||
.dx11 = {
|
||||
.m_location = location,
|
||||
.m_size = arg.size,
|
||||
.m_buffer = arg.buffer,
|
||||
}
|
||||
};
|
||||
|
||||
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 = {.dx11 =
|
||||
{
|
||||
.m_location = arg.location.samplerIndex,
|
||||
.m_size = arg.size,
|
||||
.m_buffer = arg.buffer,
|
||||
}},
|
||||
.m_value = {
|
||||
.name_hash = arg.u.nameHash,
|
||||
}
|
||||
{
|
||||
const techset::CommonShaderArgValue value{
|
||||
.name_hash = arg.u.nameHash,
|
||||
};
|
||||
const techset::CommonShaderArgLocationDx11 location{
|
||||
.texture_index = arg.location.textureIndex,
|
||||
.sampler_index = arg.location.samplerIndex,
|
||||
};
|
||||
const techset::CommonShaderArgDestination destination = {
|
||||
.dx11 = {
|
||||
.m_location = location,
|
||||
.m_size = arg.size,
|
||||
.m_buffer = arg.buffer,
|
||||
}
|
||||
};
|
||||
|
||||
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 = {.dx11 =
|
||||
{
|
||||
.m_location = arg.location.offset,
|
||||
.m_size = arg.size,
|
||||
.m_buffer = arg.buffer,
|
||||
}},
|
||||
.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 = {.dx11 =
|
||||
{
|
||||
.m_location = arg.location.offset,
|
||||
.m_size = arg.size,
|
||||
.m_buffer = arg.buffer,
|
||||
}},
|
||||
.m_value = {},
|
||||
const techset::CommonShaderArgLocationDx11 location{
|
||||
.constant_buffer_offset = arg.location.offset,
|
||||
};
|
||||
const techset::CommonShaderArgDestination destination = {
|
||||
.dx11 = {
|
||||
.m_location = location,
|
||||
.m_size = arg.size,
|
||||
.m_buffer = arg.buffer,
|
||||
}
|
||||
};
|
||||
|
||||
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)
|
||||
@@ -186,34 +203,16 @@ namespace
|
||||
|
||||
if (vertexShader->prog.loadDef.program)
|
||||
{
|
||||
result.m_shader_bin = vertexShader->prog.loadDef.program;
|
||||
result.m_shader_bin_size = vertexShader->prog.loadDef.programSize;
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
techset::CommonTechniqueShader ConvertToCommonShader(const MaterialPass& pass, const MaterialPixelShader* pixelShader)
|
||||
techset::CommonTechniqueShader ConvertToCommonShader(const MaterialPixelShader* pixelShader)
|
||||
{
|
||||
techset::CommonTechniqueShader result{};
|
||||
if (!pixelShader)
|
||||
@@ -224,30 +223,10 @@ namespace
|
||||
|
||||
if (pixelShader->prog.loadDef.program)
|
||||
{
|
||||
result.m_shader_bin = pixelShader->prog.loadDef.program;
|
||||
result.m_shader_bin_size = pixelShader->prog.loadDef.programSize;
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -255,26 +234,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::DX11,
|
||||
.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)
|
||||
@@ -287,7 +270,8 @@ namespace
|
||||
{
|
||||
const auto commonTechnique = ConvertToCommonTechnique(*technique);
|
||||
|
||||
techset::DumpCommonTechnique(context, commonTechnique, commonCodeSourceInfos, commonRoutingInfos, *materialConstantState);
|
||||
techset::DumpCommonTechnique(
|
||||
context, commonTechnique, techset::DxVersion::DX11, commonCodeSourceInfos, commonRoutingInfos, *materialConstantState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user