mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-02-14 03:13:03 +00:00
wip
This commit is contained in:
@@ -277,6 +277,11 @@ namespace T5
|
||||
};
|
||||
static_assert(std::extent_v<decltype(streamRoutingDestinations)> == STREAM_DST_COUNT);
|
||||
|
||||
static inline techset::CommonStreamRoutingInfos commonRoutingInfos(streamRoutingSources,
|
||||
std::extent_v<decltype(streamRoutingSources)>,
|
||||
streamRoutingDestinations,
|
||||
std::extent_v<decltype(streamRoutingDestinations)>);
|
||||
|
||||
static techset::CommonCodeConstSourceInfo commonCodeConstSources[]{
|
||||
{
|
||||
.value = CONST_SRC_CODE_LIGHT_POSITION,
|
||||
@@ -1734,6 +1739,26 @@ namespace T5
|
||||
},
|
||||
};
|
||||
|
||||
// See MaterialShaderArgumentType
|
||||
static inline techset::CommonShaderArgumentType commonArgumentTypes[]{
|
||||
{.m_shader_type = techset::CommonTechniqueShaderType::VERTEX, .m_value_type = techset::CommonShaderValueType::MATERIAL_CONST },
|
||||
{.m_shader_type = techset::CommonTechniqueShaderType::VERTEX, .m_value_type = techset::CommonShaderValueType::LITERAL_CONST },
|
||||
{.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::MATERIAL_SAMPLER},
|
||||
{.m_shader_type = techset::CommonTechniqueShaderType::VERTEX, .m_value_type = techset::CommonShaderValueType::CODE_CONST },
|
||||
{.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::CODE_SAMPLER },
|
||||
{.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::CODE_CONST },
|
||||
{.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::MATERIAL_CONST },
|
||||
{.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::LITERAL_CONST },
|
||||
};
|
||||
static_assert(std::extent_v<decltype(commonArgumentTypes)> == MLT_ARG_COUNT);
|
||||
|
||||
static inline techset::CommonCodeSourceInfos commonCodeSourceInfos(commonCodeConstSources,
|
||||
std::extent_v<decltype(commonCodeConstSources)>,
|
||||
commonCodeSamplerSources,
|
||||
std::extent_v<decltype(commonCodeSamplerSources)>,
|
||||
commonArgumentTypes,
|
||||
std::extent_v<decltype(commonArgumentTypes)>);
|
||||
|
||||
inline MaterialTypeInfo g_materialTypeInfo[]{
|
||||
{"", "" },
|
||||
{"m/", "m_" },
|
||||
|
||||
@@ -190,6 +190,11 @@ namespace T6
|
||||
};
|
||||
static_assert(std::extent_v<decltype(streamRoutingDestinations)> == STREAM_DST_COUNT);
|
||||
|
||||
static inline techset::CommonStreamRoutingInfos commonRoutingInfos(streamRoutingSources,
|
||||
std::extent_v<decltype(streamRoutingSources)>,
|
||||
streamRoutingDestinations,
|
||||
std::extent_v<decltype(streamRoutingDestinations)>);
|
||||
|
||||
static inline techset::CommonCodeConstSourceInfo commonCodeConstSources[]{
|
||||
{
|
||||
.value = CONST_SRC_CODE_LIGHT_POSITION,
|
||||
@@ -214,6 +219,7 @@ namespace T6
|
||||
.accessor = "lightSpotFactors",
|
||||
.arrayCount = 0,
|
||||
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
|
||||
.techFlags = TECHNIQUE_FLAG_10,
|
||||
},
|
||||
{
|
||||
.value = CONST_SRC_CODE_LIGHT_ATTENUATION,
|
||||
@@ -544,6 +550,7 @@ namespace T6
|
||||
.accessor = "particleCloudVelWorld",
|
||||
.arrayCount = 0,
|
||||
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT,
|
||||
.techFlags = TECHNIQUE_FLAG_100,
|
||||
},
|
||||
{
|
||||
.value = CONST_SRC_CODE_DEPTH_FROM_CLIP,
|
||||
@@ -1538,11 +1545,13 @@ namespace T6
|
||||
.value = TEXTURE_SRC_CODE_LIGHTMAP_PRIMARY,
|
||||
.accessor = "lightmapSamplerPrimary",
|
||||
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM,
|
||||
.customSamplerIndex = CUSTOM_SAMPLER_LIGHTMAP_PRIMARY,
|
||||
},
|
||||
{
|
||||
.value = TEXTURE_SRC_CODE_LIGHTMAP_SECONDARY,
|
||||
.accessor = "lightmapSamplerSecondary",
|
||||
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM,
|
||||
.customSamplerIndex = CUSTOM_SAMPLER_LIGHTMAP_SECONDARY,
|
||||
},
|
||||
{
|
||||
.value = TEXTURE_SRC_CODE_SHADOWMAP_SUN,
|
||||
@@ -1563,11 +1572,13 @@ namespace T6
|
||||
.value = TEXTURE_SRC_CODE_RESOLVED_POST_SUN,
|
||||
.accessor = "resolvedPostSun",
|
||||
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
|
||||
.techFlags = TECHNIQUE_FLAG_1,
|
||||
},
|
||||
{
|
||||
.value = TEXTURE_SRC_CODE_RESOLVED_SCENE,
|
||||
.accessor = "resolvedScene",
|
||||
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
|
||||
.techFlags = TECHNIQUE_FLAG_2,
|
||||
},
|
||||
{
|
||||
.value = TEXTURE_SRC_CODE_POST_EFFECT_SRC,
|
||||
@@ -1608,16 +1619,19 @@ namespace T6
|
||||
.value = TEXTURE_SRC_CODE_FLOATZ,
|
||||
.accessor = "floatZSampler",
|
||||
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
|
||||
.techFlags = TECHNIQUE_FLAG_40,
|
||||
},
|
||||
{
|
||||
.value = TEXTURE_SRC_CODE_PROCESSED_FLOATZ,
|
||||
.accessor = "processedFloatZSampler",
|
||||
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
|
||||
.techFlags = TECHNIQUE_FLAG_40,
|
||||
},
|
||||
{
|
||||
.value = TEXTURE_SRC_CODE_RAW_FLOATZ,
|
||||
.accessor = "rawFloatZSampler",
|
||||
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY,
|
||||
.techFlags = TECHNIQUE_FLAG_40,
|
||||
},
|
||||
{
|
||||
.value = TEXTURE_SRC_CODE_STENCIL,
|
||||
@@ -1648,6 +1662,7 @@ namespace T6
|
||||
.value = TEXTURE_SRC_CODE_REFLECTION_PROBE,
|
||||
.accessor = "reflectionProbeSampler",
|
||||
.updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM,
|
||||
.customSamplerIndex = CUSTOM_SAMPLER_REFLECTION_PROBE,
|
||||
},
|
||||
{
|
||||
.value = TEXTURE_SRC_CODE_FEATHER_FLOAT_Z,
|
||||
@@ -1791,6 +1806,26 @@ namespace T6
|
||||
},
|
||||
};
|
||||
|
||||
// See MaterialShaderArgumentType
|
||||
static inline techset::CommonShaderArgumentType commonArgumentTypes[]{
|
||||
{.m_shader_type = techset::CommonTechniqueShaderType::VERTEX, .m_value_type = techset::CommonShaderValueType::MATERIAL_CONST },
|
||||
{.m_shader_type = techset::CommonTechniqueShaderType::VERTEX, .m_value_type = techset::CommonShaderValueType::LITERAL_CONST },
|
||||
{.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::MATERIAL_SAMPLER},
|
||||
{.m_shader_type = techset::CommonTechniqueShaderType::VERTEX, .m_value_type = techset::CommonShaderValueType::CODE_CONST },
|
||||
{.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::CODE_SAMPLER },
|
||||
{.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::CODE_CONST },
|
||||
{.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::MATERIAL_CONST },
|
||||
{.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::LITERAL_CONST },
|
||||
};
|
||||
static_assert(std::extent_v<decltype(commonArgumentTypes)> == MLT_ARG_COUNT);
|
||||
|
||||
static inline techset::CommonCodeSourceInfos commonCodeSourceInfos(commonCodeConstSources,
|
||||
std::extent_v<decltype(commonCodeConstSources)>,
|
||||
commonCodeSamplerSources,
|
||||
std::extent_v<decltype(commonCodeSamplerSources)>,
|
||||
commonArgumentTypes,
|
||||
std::extent_v<decltype(commonArgumentTypes)>);
|
||||
|
||||
static inline MaterialTypeInfo g_materialTypeInfo[]{
|
||||
{"", "" },
|
||||
{"m/", "m_" },
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
#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 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_argument_types(argumentTypeCount)
|
||||
{
|
||||
std::copy(codeConstSourceInfos, &codeConstSourceInfos[codeConstCount], m_code_const_source_infos.data());
|
||||
std::ranges::sort(m_code_const_source_infos,
|
||||
@@ -24,6 +28,18 @@ namespace techset
|
||||
{
|
||||
return a.value < b.value;
|
||||
});
|
||||
|
||||
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 +71,33 @@ namespace techset
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
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 +107,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 +160,144 @@ 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;
|
||||
}
|
||||
|
||||
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);
|
||||
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))
|
||||
{
|
||||
}
|
||||
|
||||
void CommonVertexDeclaration::SortRoutingEntries()
|
||||
{
|
||||
std::ranges::sort(m_routing,
|
||||
[](const CommonStreamRouting& r1, const CommonStreamRouting& r2)
|
||||
{
|
||||
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
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace techset
|
||||
@@ -27,12 +28,35 @@ 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
|
||||
};
|
||||
|
||||
enum class CommonCodeSourceUpdateFrequency : std::uint8_t
|
||||
{
|
||||
PER_PRIM,
|
||||
PER_OBJECT,
|
||||
RARELY,
|
||||
CUSTOM,
|
||||
IGNORE,
|
||||
|
||||
COUNT
|
||||
};
|
||||
|
||||
struct CommonCodeConstSourceInfo
|
||||
@@ -41,6 +65,7 @@ namespace techset
|
||||
const char* accessor;
|
||||
std::uint8_t arrayCount;
|
||||
CommonCodeSourceUpdateFrequency updateFrequency;
|
||||
std::optional<unsigned> techFlags;
|
||||
};
|
||||
|
||||
struct CommonCodeSamplerSourceInfo
|
||||
@@ -48,6 +73,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 +99,26 @@ namespace techset
|
||||
CommonCodeSourceInfos(const CommonCodeConstSourceInfo* codeConstSourceInfos,
|
||||
size_t codeConstCount,
|
||||
const CommonCodeSamplerSourceInfo* codeSamplerSourceInfos,
|
||||
size_t codeSamplerCount);
|
||||
size_t codeSamplerCount,
|
||||
const CommonShaderArgumentType* argumentTypes,
|
||||
size_t argumentTypeCount);
|
||||
|
||||
[[nodiscard]] std::optional<CommonCodeConstSourceInfo> GetInfoForCodeConstSource(CommonCodeConstSource codeConstSource) const;
|
||||
[[nodiscard]] std::optional<CommonCodeSamplerSourceInfo> GetInfoForCodeSamplerSource(CommonCodeSamplerSource codeSamplerSource) 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_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 +134,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
|
||||
@@ -115,31 +178,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;
|
||||
};
|
||||
@@ -147,39 +205,69 @@ namespace techset
|
||||
class CommonVertexDeclaration
|
||||
{
|
||||
public:
|
||||
CommonVertexDeclaration() = default;
|
||||
explicit CommonVertexDeclaration(std::vector<CommonStreamRouting> routing);
|
||||
|
||||
void SortRoutingEntries();
|
||||
|
||||
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
|
||||
|
||||
67
src/ObjCommon/Techset/CommonVertexDeclCreator.cpp
Normal file
67
src/ObjCommon/Techset/CommonVertexDeclCreator.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "CommonVertexDeclCreator.h"
|
||||
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace
|
||||
{
|
||||
bool NextAbbreviation(const std::string& assetName, std::string& abbreviation, size_t& offset)
|
||||
{
|
||||
if (offset >= assetName.size())
|
||||
return false;
|
||||
|
||||
if (offset + 1 < assetName.size() && isdigit(assetName[offset + 1]))
|
||||
{
|
||||
abbreviation = std::string(assetName, offset, 2);
|
||||
offset += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
abbreviation = std::string(assetName, offset, 1);
|
||||
offset += 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace techset
|
||||
{
|
||||
std::optional<CommonVertexDeclaration> CreateVertexDeclFromName(const std::string& name, const CommonStreamRoutingInfos& routingInfos)
|
||||
{
|
||||
CommonVertexDeclaration result;
|
||||
size_t currentOffset = 0u;
|
||||
|
||||
std::string sourceAbbreviation;
|
||||
while (NextAbbreviation(name, sourceAbbreviation, currentOffset))
|
||||
{
|
||||
std::string destinationAbbreviation;
|
||||
if (!NextAbbreviation(name, destinationAbbreviation, currentOffset))
|
||||
{
|
||||
con::error("Failed to detect vertex decl destination abbreviation: {}", name);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const auto maybeSource = routingInfos.GetSourceByAbbreviation(sourceAbbreviation);
|
||||
if (!maybeSource)
|
||||
{
|
||||
con::error("Unknown vertex decl source abbreviation: {}", sourceAbbreviation);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const auto maybeDestination = routingInfos.GetDestinationByAbbreviation(sourceAbbreviation);
|
||||
if (!maybeDestination)
|
||||
{
|
||||
con::error("Unknown vertex decl destination abbreviation: {}", destinationAbbreviation);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
result.m_routing.emplace_back(*maybeSource, *maybeDestination);
|
||||
}
|
||||
|
||||
result.SortRoutingEntries();
|
||||
|
||||
return result;
|
||||
}
|
||||
} // namespace techset
|
||||
11
src/ObjCommon/Techset/CommonVertexDeclCreator.h
Normal file
11
src/ObjCommon/Techset/CommonVertexDeclCreator.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "CommonTechnique.h"
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace techset
|
||||
{
|
||||
std::optional<CommonVertexDeclaration> CreateVertexDeclFromName(const std::string& name, const CommonStreamRoutingInfos& routingInfos);
|
||||
}
|
||||
Reference in New Issue
Block a user