mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-09-22 05:47:06 +00:00
chore: add more details to common techset infos in t5,t6
This commit is contained in:
@@ -1,15 +1,22 @@
|
||||
#include "CommonTechnique.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
namespace techset
|
||||
{
|
||||
CommonCodeSourceInfos::CommonCodeSourceInfos(const CommonCodeConstSourceInfo* codeConstSourceInfos,
|
||||
const size_t codeConstCount,
|
||||
const CommonCodeSamplerSourceInfo* codeSamplerSourceInfos,
|
||||
const size_t codeSamplerCount)
|
||||
const size_t codeSamplerCount,
|
||||
const char** ignoreArgAccessors,
|
||||
const size_t ignoredArgAccessorCount,
|
||||
const CommonShaderArgumentType* argumentTypes,
|
||||
const size_t argumentTypeCount)
|
||||
: m_code_const_source_infos(codeConstCount),
|
||||
m_code_sampler_source_infos(codeSamplerCount)
|
||||
m_code_sampler_source_infos(codeSamplerCount),
|
||||
m_ignored_arg_accessors(ignoredArgAccessorCount),
|
||||
m_argument_types(argumentTypeCount)
|
||||
{
|
||||
std::copy(codeConstSourceInfos, &codeConstSourceInfos[codeConstCount], m_code_const_source_infos.data());
|
||||
std::ranges::sort(m_code_const_source_infos,
|
||||
@@ -24,6 +31,21 @@ namespace techset
|
||||
{
|
||||
return a.value < b.value;
|
||||
});
|
||||
|
||||
for (size_t i = 0; i < ignoredArgAccessorCount; i++)
|
||||
m_ignored_arg_accessors.emplace(ignoreArgAccessors[i]);
|
||||
|
||||
std::copy(argumentTypes, &argumentTypes[argumentTypeCount], m_argument_types.data());
|
||||
|
||||
for (const auto& codeConstInfo : m_code_const_source_infos)
|
||||
{
|
||||
m_code_const_lookup.emplace(codeConstInfo.accessor, codeConstInfo.value);
|
||||
}
|
||||
|
||||
for (const auto& codeSamplerInfo : m_code_sampler_source_infos)
|
||||
{
|
||||
m_code_sampler_lookup.emplace(codeSamplerInfo.accessor, codeSamplerInfo.value);
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<CommonCodeConstSourceInfo> CommonCodeSourceInfos::GetInfoForCodeConstSource(const CommonCodeConstSource codeConstSource) const
|
||||
@@ -55,6 +77,38 @@ namespace techset
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
bool CommonCodeSourceInfos::IsArgAccessorIgnored(const std::string& accessor) const
|
||||
{
|
||||
return m_ignored_arg_accessors.contains(accessor);
|
||||
}
|
||||
|
||||
std::optional<CommonCodeConstSource> CommonCodeSourceInfos::GetCodeConstSourceForAccessor(const std::string& accessor) const
|
||||
{
|
||||
const auto foundEntry = m_code_const_lookup.find(accessor);
|
||||
if (foundEntry == m_code_const_lookup.end())
|
||||
return std::nullopt;
|
||||
|
||||
return foundEntry->second;
|
||||
}
|
||||
|
||||
std::optional<CommonCodeSamplerSource> CommonCodeSourceInfos::GetCodeSamplerSourceForAccessor(const std::string& accessor) const
|
||||
{
|
||||
const auto foundEntry = m_code_sampler_lookup.find(accessor);
|
||||
if (foundEntry == m_code_sampler_lookup.end())
|
||||
return std::nullopt;
|
||||
|
||||
return foundEntry->second;
|
||||
}
|
||||
|
||||
std::optional<size_t> CommonCodeSourceInfos::GetArgumentTypeNumericValue(const CommonShaderArgumentType& argumentType) const
|
||||
{
|
||||
const auto foundValue = std::ranges::find(m_argument_types, argumentType);
|
||||
if (foundValue == m_argument_types.end())
|
||||
return std::nullopt;
|
||||
|
||||
return static_cast<size_t>(foundValue - m_argument_types.begin());
|
||||
}
|
||||
|
||||
CommonStreamRoutingInfos::CommonStreamRoutingInfos(const CommonStreamRoutingSourceInfo* sourceInfos,
|
||||
const size_t sourceCount,
|
||||
const CommonStreamRoutingDestinationInfo* destinationNames,
|
||||
@@ -64,6 +118,18 @@ namespace techset
|
||||
{
|
||||
std::copy(sourceInfos, &sourceInfos[sourceCount], m_sources.data());
|
||||
std::copy(destinationNames, &destinationNames[destinationCount], m_destinations.data());
|
||||
|
||||
for (size_t i = 0; i < sourceCount; i++)
|
||||
{
|
||||
m_source_name_lookup[sourceInfos[i].name] = static_cast<CommonStreamSource>(i);
|
||||
m_source_abbreviation_lookup[sourceInfos[i].abbreviation] = static_cast<CommonStreamSource>(i);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < destinationCount; i++)
|
||||
{
|
||||
m_destination_name_lookup[destinationNames[i].name] = static_cast<CommonStreamDestination>(i);
|
||||
m_destination_abbreviation_lookup[destinationNames[i].abbreviation] = static_cast<CommonStreamDestination>(i);
|
||||
}
|
||||
}
|
||||
|
||||
const char* CommonStreamRoutingInfos::GetSourceName(const CommonStreamSource source) const
|
||||
@@ -105,4 +171,40 @@ namespace techset
|
||||
|
||||
return m_destinations[destination].abbreviation;
|
||||
}
|
||||
|
||||
std::optional<CommonStreamSource> CommonStreamRoutingInfos::GetSourceByName(const std::string& name) const
|
||||
{
|
||||
const auto foundSource = m_source_name_lookup.find(name);
|
||||
if (foundSource != m_source_name_lookup.end())
|
||||
return foundSource->second;
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<CommonStreamSource> CommonStreamRoutingInfos::GetSourceByAbbreviation(const std::string& abbreviation) const
|
||||
{
|
||||
const auto foundSource = m_source_abbreviation_lookup.find(abbreviation);
|
||||
if (foundSource != m_source_abbreviation_lookup.end())
|
||||
return foundSource->second;
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<CommonStreamDestination> CommonStreamRoutingInfos::GetDestinationByName(const std::string& name) const
|
||||
{
|
||||
const auto foundDestination = m_destination_name_lookup.find(name);
|
||||
if (foundDestination != m_destination_name_lookup.end())
|
||||
return foundDestination->second;
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<CommonStreamDestination> CommonStreamRoutingInfos::GetDestinationByAbbreviation(const std::string& abbreviation) const
|
||||
{
|
||||
const auto foundDestination = m_destination_abbreviation_lookup.find(abbreviation);
|
||||
if (foundDestination != m_destination_abbreviation_lookup.end())
|
||||
return foundDestination->second;
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
} // namespace techset
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace techset
|
||||
@@ -27,12 +30,46 @@ namespace techset
|
||||
const char* abbreviation;
|
||||
};
|
||||
|
||||
enum class CommonTechniqueShaderType : std::uint8_t
|
||||
{
|
||||
VERTEX,
|
||||
PIXEL
|
||||
};
|
||||
|
||||
enum class CommonShaderValueType : 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
|
||||
};
|
||||
|
||||
constexpr bool IsConstValueType(const CommonShaderValueType valueType)
|
||||
{
|
||||
return valueType == CommonShaderValueType::LITERAL_CONST || valueType == CommonShaderValueType::MATERIAL_CONST
|
||||
|| valueType == CommonShaderValueType::CODE_CONST;
|
||||
}
|
||||
|
||||
constexpr bool IsSamplerValueType(const CommonShaderValueType valueType)
|
||||
{
|
||||
return valueType == CommonShaderValueType::MATERIAL_SAMPLER || valueType == CommonShaderValueType::CODE_SAMPLER;
|
||||
}
|
||||
|
||||
enum class CommonCodeSourceUpdateFrequency : std::uint8_t
|
||||
{
|
||||
PER_PRIM,
|
||||
PER_OBJECT,
|
||||
RARELY,
|
||||
CUSTOM,
|
||||
IGNORE,
|
||||
|
||||
COUNT
|
||||
};
|
||||
|
||||
struct CommonCodeConstSourceInfo
|
||||
@@ -41,6 +78,8 @@ namespace techset
|
||||
const char* accessor;
|
||||
std::uint8_t arrayCount;
|
||||
CommonCodeSourceUpdateFrequency updateFrequency;
|
||||
std::optional<unsigned> techFlags;
|
||||
std::optional<CommonCodeConstSource> transposedMatrix;
|
||||
};
|
||||
|
||||
struct CommonCodeSamplerSourceInfo
|
||||
@@ -48,6 +87,24 @@ namespace techset
|
||||
CommonCodeSamplerSource value;
|
||||
const char* accessor;
|
||||
CommonCodeSourceUpdateFrequency updateFrequency;
|
||||
std::optional<unsigned> techFlags;
|
||||
std::optional<unsigned> customSamplerIndex;
|
||||
};
|
||||
|
||||
struct CommonShaderArgumentType
|
||||
{
|
||||
friend bool operator==(const CommonShaderArgumentType& lhs, const CommonShaderArgumentType& rhs)
|
||||
{
|
||||
return lhs.m_shader_type == rhs.m_shader_type && lhs.m_value_type == rhs.m_value_type;
|
||||
}
|
||||
|
||||
friend bool operator!=(const CommonShaderArgumentType& lhs, const CommonShaderArgumentType& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
CommonTechniqueShaderType m_shader_type;
|
||||
CommonShaderValueType m_value_type;
|
||||
};
|
||||
|
||||
class CommonCodeSourceInfos
|
||||
@@ -56,14 +113,36 @@ namespace techset
|
||||
CommonCodeSourceInfos(const CommonCodeConstSourceInfo* codeConstSourceInfos,
|
||||
size_t codeConstCount,
|
||||
const CommonCodeSamplerSourceInfo* codeSamplerSourceInfos,
|
||||
size_t codeSamplerCount);
|
||||
size_t codeSamplerCount,
|
||||
const char** ignoreArgAccessors,
|
||||
size_t ignoredArgAccessorCount,
|
||||
const CommonShaderArgumentType* argumentTypes,
|
||||
size_t argumentTypeCount);
|
||||
|
||||
[[nodiscard]] std::optional<CommonCodeConstSourceInfo> GetInfoForCodeConstSource(CommonCodeConstSource codeConstSource) const;
|
||||
[[nodiscard]] std::optional<CommonCodeSamplerSourceInfo> GetInfoForCodeSamplerSource(CommonCodeSamplerSource codeSamplerSource) const;
|
||||
|
||||
/**
|
||||
* \brief Some games like T6 do not create args for certain variables. This checks whether an accessor identifies one of these variables.
|
||||
* \param accessor The accessor of the variable
|
||||
* \return \c true if the accessor should be ignored
|
||||
*/
|
||||
[[nodiscard]] bool IsArgAccessorIgnored(const std::string& accessor) const;
|
||||
|
||||
[[nodiscard]] std::optional<CommonCodeConstSource> GetCodeConstSourceForAccessor(const std::string& accessor) const;
|
||||
[[nodiscard]] std::optional<CommonCodeSamplerSource> GetCodeSamplerSourceForAccessor(const std::string& accessor) const;
|
||||
|
||||
[[nodiscard]] std::optional<size_t> GetArgumentTypeNumericValue(const CommonShaderArgumentType& argumentType) const;
|
||||
|
||||
private:
|
||||
std::vector<CommonCodeConstSourceInfo> m_code_const_source_infos;
|
||||
std::vector<CommonCodeSamplerSourceInfo> m_code_sampler_source_infos;
|
||||
std::unordered_set<std::string> m_ignored_arg_accessors;
|
||||
|
||||
std::unordered_map<std::string, CommonCodeConstSource> m_code_const_lookup;
|
||||
std::unordered_map<std::string, CommonCodeSamplerSource> m_code_sampler_lookup;
|
||||
|
||||
std::vector<CommonShaderArgumentType> m_argument_types;
|
||||
};
|
||||
|
||||
class CommonStreamRoutingInfos
|
||||
@@ -79,10 +158,18 @@ namespace techset
|
||||
[[nodiscard]] bool IsSourceOptional(CommonStreamSource source) const;
|
||||
[[nodiscard]] const char* GetDestinationName(CommonStreamDestination destination) const;
|
||||
[[nodiscard]] const char* GetDestinationAbbreviation(CommonStreamDestination destination) const;
|
||||
[[nodiscard]] std::optional<CommonStreamSource> GetSourceByName(const std::string& name) const;
|
||||
[[nodiscard]] std::optional<CommonStreamSource> GetSourceByAbbreviation(const std::string& abbreviation) const;
|
||||
[[nodiscard]] std::optional<CommonStreamDestination> GetDestinationByName(const std::string& name) const;
|
||||
[[nodiscard]] std::optional<CommonStreamDestination> GetDestinationByAbbreviation(const std::string& abbreviation) const;
|
||||
|
||||
private:
|
||||
std::vector<CommonStreamRoutingSourceInfo> m_sources;
|
||||
std::vector<CommonStreamRoutingDestinationInfo> m_destinations;
|
||||
std::unordered_map<std::string, CommonStreamSource> m_source_name_lookup;
|
||||
std::unordered_map<std::string, CommonStreamDestination> m_destination_name_lookup;
|
||||
std::unordered_map<std::string, CommonStreamSource> m_source_abbreviation_lookup;
|
||||
std::unordered_map<std::string, CommonStreamDestination> m_destination_abbreviation_lookup;
|
||||
};
|
||||
|
||||
union CommonShaderArgValue
|
||||
|
||||
Reference in New Issue
Block a user