2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-04-07 12:18:40 +00:00

fix: errors with common techset dumping

* not respecting transposing matrices
* not respecting arrays
This commit is contained in:
Jan Laupetin
2026-02-27 23:04:42 +01:00
parent 86ae57578b
commit 38abe459e1
6 changed files with 470 additions and 367 deletions

View File

@@ -208,6 +208,48 @@ namespace techset
return std::nullopt;
}
CommonShaderArg::CommonShaderArg(const CommonShaderArgumentType type, const CommonShaderArgDestination& destination, const CommonShaderArgValue& value)
: m_type(type),
m_destination(destination),
m_value(value)
{
}
CommonCodeSourceUpdateFrequency CommonShaderArg::GetFrequency(const CommonCodeSourceInfos& infos) const
{
switch (m_type.m_value_type)
{
case CommonShaderValueType::CODE_CONST:
{
const auto info = infos.GetInfoForCodeConstSource(m_value.code_const_source.m_index);
assert(info);
return info->updateFrequency;
}
case CommonShaderValueType::CODE_SAMPLER:
{
const auto info = infos.GetInfoForCodeSamplerSource(m_value.code_sampler_source);
assert(info);
return info->updateFrequency;
}
case CommonShaderValueType::MATERIAL_CONST:
case CommonShaderValueType::LITERAL_CONST:
case CommonShaderValueType::MATERIAL_SAMPLER:
return CommonCodeSourceUpdateFrequency::RARELY;
default:
assert(false);
return CommonCodeSourceUpdateFrequency::RARELY;
}
}
CommonStreamRouting::CommonStreamRouting(const CommonStreamSource source, const CommonStreamDestination destination)
: m_source(source),
m_destination(destination)
{
}
CommonVertexDeclaration::CommonVertexDeclaration(std::vector<CommonStreamRouting> routing)
: m_routing(std::move(routing))
{
@@ -221,4 +263,52 @@ namespace techset
return r1.m_source < r2.m_source;
});
}
CommonTechniqueShader::CommonTechniqueShader()
: m_type(CommonTechniqueShaderType::VERTEX)
{
}
CommonTechniqueShader::CommonTechniqueShader(const CommonTechniqueShaderType type, std::string name)
: m_type(type),
m_name(std::move(name))
{
}
CommonPass::CommonPass(const uint32_t samplerFlags,
std::string stateMap,
CommonTechniqueShader vertexShader,
CommonTechniqueShader pixelShader,
CommonVertexDeclaration vertexDeclaration)
: m_sampler_flags(samplerFlags),
m_state_map(std::move(stateMap)),
m_vertex_shader(std::move(vertexShader)),
m_pixel_shader(std::move(pixelShader)),
m_vertex_declaration(std::move(vertexDeclaration))
{
}
CommonPass::FrequencyCounts_t CommonPass::GetFrequencyCounts(const CommonCodeSourceInfos& infos) const
{
FrequencyCounts_t result;
for (auto& count : result)
count = 0;
for (auto& arg : m_args)
result[std::to_underlying(arg.GetFrequency(infos))]++;
return result;
}
CommonTechnique::CommonTechnique(std::string name)
: m_name(std::move(name)),
m_flags(0)
{
}
CommonTechnique::CommonTechnique(std::string name, const uint64_t flags)
: m_name(std::move(name)),
m_flags(flags)
{
}
} // namespace techset

View File

@@ -172,10 +172,17 @@ namespace techset
std::unordered_map<std::string, CommonStreamDestination> m_destination_abbreviation_lookup;
};
struct CommonShaderArgCodeConstValue
{
CommonCodeConstSource m_index;
unsigned m_first_row;
unsigned m_row_count;
};
union CommonShaderArgValue
{
std::array<float, 4> literal_value;
CommonCodeConstSource code_const_source;
CommonShaderArgCodeConstValue code_const_source;
CommonCodeSamplerSource code_sampler_source;
unsigned name_hash;
};
@@ -186,12 +193,23 @@ namespace techset
unsigned m_destination_register;
};
// In case of a constant: Offset in constant buffer
// In case of a sampler: Index of sampler + index of texture
union CommonShaderArgLocationDx11
{
unsigned constant_buffer_offset;
struct
{
unsigned texture_index;
unsigned sampler_index;
};
};
class CommonShaderArgDestinationDx11
{
public:
// In case of a constant: Offset in constant buffer
// In case of a sampler: Index of sampler
unsigned m_location;
CommonShaderArgLocationDx11 m_location;
unsigned m_size;
unsigned m_buffer;
};
@@ -202,31 +220,26 @@ namespace techset
CommonShaderArgDestinationDx11 dx11;
};
enum class CommonShaderArgType : std::uint8_t
{
// Value is set to a float4 value in the pass
LITERAL_CONST,
// Value is set to a float4 value in the material
MATERIAL_CONST,
// Value is set to a float4 value calculated in code
CODE_CONST,
// Value is set to a sampler from the material
MATERIAL_SAMPLER,
// Value is set to a sampler generated in code
CODE_SAMPLER
};
class CommonShaderArg
{
public:
CommonShaderArgType m_type;
CommonShaderArg() = default;
CommonShaderArg(CommonShaderArgumentType type, const CommonShaderArgDestination& destination, const CommonShaderArgValue& value);
[[nodiscard]] CommonCodeSourceUpdateFrequency GetFrequency(const CommonCodeSourceInfos& infos) const;
CommonShaderArgumentType m_type;
CommonShaderArgDestination m_destination;
CommonShaderArgValue m_value;
std::optional<CommonCodeSourceUpdateFrequency> m_bin;
};
class CommonStreamRouting
{
public:
CommonStreamRouting() = default;
CommonStreamRouting(CommonStreamSource source, CommonStreamDestination destination);
CommonStreamSource m_source;
CommonStreamDestination m_destination;
};
@@ -242,36 +255,61 @@ namespace techset
std::vector<CommonStreamRouting> m_routing;
};
class CommonTechniqueShaderBin
{
public:
const void* m_shader_bin;
size_t m_shader_bin_size;
};
class CommonTechniqueShader
{
public:
CommonTechniqueShader();
CommonTechniqueShader(CommonTechniqueShaderType type, std::string name);
CommonTechniqueShaderType m_type;
std::string m_name;
const void* m_shader_bin;
size_t m_shader_bin_size;
std::optional<CommonTechniqueShaderBin> m_bin;
};
class CommonPass
{
public:
using FrequencyCounts_t = std::array<size_t, std::to_underlying(CommonCodeSourceUpdateFrequency::COUNT)>;
CommonPass() = default;
CommonPass(uint32_t samplerFlags,
std::string stateMap,
CommonTechniqueShader vertexShader,
CommonTechniqueShader pixelShader,
CommonVertexDeclaration vertexDeclaration);
[[nodiscard]] FrequencyCounts_t GetFrequencyCounts(const CommonCodeSourceInfos& infos) const;
uint32_t m_sampler_flags;
std::string m_state_map;
CommonTechniqueShader m_vertex_shader;
CommonTechniqueShader m_pixel_shader;
CommonVertexDeclaration m_vertex_declaration;
std::vector<CommonShaderArg> m_args;
};
class CommonTechnique
{
public:
CommonTechnique() = default;
explicit CommonTechnique(std::string name);
CommonTechnique(std::string name, uint64_t flags);
std::string m_name;
uint64_t m_flags;
std::vector<CommonPass> m_passes;
};
enum class DxVersion : std::uint8_t
{
DX9,
DX11
};
class CommonPass
{
public:
uint32_t m_sampler_flags;
DxVersion m_dx_version;
CommonTechniqueShader m_vertex_shader;
CommonTechniqueShader m_pixel_shader;
CommonVertexDeclaration m_vertex_declaration;
};
class CommonTechnique
{
public:
std::string m_name;
uint64_t m_flags;
std::vector<CommonPass> m_passes;
};
} // namespace techset