From 18ccbb91802a746c7e6a0f3d12063d98da8c0779 Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Thu, 30 Oct 2025 22:26:33 +0100 Subject: [PATCH 1/5] feat: dump techsets for t6 --- src/Common/Game/T6/T6_Assets.h | 60 +++++----- .../IW4/{ => Techset}/TechsetConstantsIW4.h | 0 .../T6/{ => Techset}/TechsetConstantsT6.h | 0 src/ObjCommon/Techset/CommonTechnique.cpp | 0 src/ObjCommon/Techset/CommonTechnique.h | 32 ++++++ src/ObjCommon/Techset/CommonTechset.cpp | 22 ++++ src/ObjCommon/Techset/CommonTechset.h | 27 +++++ .../Game/IW4/Material/CompilerMaterialIW4.cpp | 2 +- .../Game/IW4/Techset/CompilerTechsetIW4.cpp | 2 +- .../IW4/Techset/CompilerVertexDeclIW4.cpp | 2 +- .../Material/MaterialDecompilingDumperIW4.cpp | 3 +- .../Game/IW4/Techset/TechsetDumperIW4.cpp | 107 +++++------------- .../Game/T6/Techset/TechsetDumperT6.cpp | 89 +++++++++++++-- .../Techset/CommonTechniqueDumper.cpp | 0 .../Techset/CommonTechniqueDumper.h | 9 ++ .../Techset/CommonTechsetDumper.cpp | 92 +++++++++++++++ src/ObjWriting/Techset/CommonTechsetDumper.h | 9 ++ .../Techset/TechniqueDumpingZoneState.cpp | 13 +++ .../Techset/TechniqueDumpingZoneState.h | 17 +++ 19 files changed, 363 insertions(+), 123 deletions(-) rename src/ObjCommon/Game/IW4/{ => Techset}/TechsetConstantsIW4.h (100%) rename src/ObjCommon/Game/T6/{ => Techset}/TechsetConstantsT6.h (100%) create mode 100644 src/ObjCommon/Techset/CommonTechnique.cpp create mode 100644 src/ObjCommon/Techset/CommonTechnique.h create mode 100644 src/ObjCommon/Techset/CommonTechset.cpp create mode 100644 src/ObjCommon/Techset/CommonTechset.h create mode 100644 src/ObjWriting/Techset/CommonTechniqueDumper.cpp create mode 100644 src/ObjWriting/Techset/CommonTechniqueDumper.h create mode 100644 src/ObjWriting/Techset/CommonTechsetDumper.cpp create mode 100644 src/ObjWriting/Techset/CommonTechsetDumper.h create mode 100644 src/ObjWriting/Techset/TechniqueDumpingZoneState.cpp create mode 100644 src/ObjWriting/Techset/TechniqueDumpingZoneState.h diff --git a/src/Common/Game/T6/T6_Assets.h b/src/Common/Game/T6/T6_Assets.h index 1a7b9b0e..366c93f7 100644 --- a/src/Common/Game/T6/T6_Assets.h +++ b/src/Common/Game/T6/T6_Assets.h @@ -3038,17 +3038,45 @@ namespace T6 void /*ID3D11RasterizerState*/* rasterizerState; }; + enum VertexShaderPrecompiledIndex : unsigned char + { + VERTEX_SHADER_NONE = 0x0, + VERTEX_SHADER_MODEL_LIT, + VERTEX_SHADER_MODEL_LIT_LIGHTMAP_VC, + VERTEX_SHADER_MODEL_UNLIT, + }; + + enum MaterialType : unsigned char + { + MTL_TYPE_DEFAULT = 0x0, + MTL_TYPE_MODEL, // m_ + MTL_TYPE_MODEL_VERTCOL, // mc_ + MTL_TYPE_MODEL_LIGHTMAP_VC, // mlv_ + MTL_TYPE_WORLD_VERTCOL, // wc_ + MTL_TYPE_PACKED_WORLD_VERTCOL, // wpc_ + MTL_TYPE_QUANT_WORLD, // wq_ + MTL_TYPE_QUANT_WORLD_VERTCOL, // wqc_ + + MTL_TYPE_COUNT, + }; + + struct MaterialTypeInfo + { + const char* materialPrefix; + const char* techniqueSetPrefix; + }; + struct MaterialPass { MaterialVertexDeclaration* vertexDecl; MaterialVertexShader* vertexShader; MaterialPixelShader* pixelShader; - char perPrimArgCount; - char perObjArgCount; - char stableArgCount; - char customSamplerFlags; - char precompiledIndex; - char materialType; + unsigned char perPrimArgCount; + unsigned char perObjArgCount; + unsigned char stableArgCount; + unsigned char customSamplerFlags; + VertexShaderPrecompiledIndex precompiledIndex; + MaterialType materialType; MaterialShaderArgument* args; }; @@ -5839,26 +5867,6 @@ namespace T6 }; }; - enum MaterialType - { - MTL_TYPE_DEFAULT = 0x0, - MTL_TYPE_MODEL = 0x1, // m_ - MTL_TYPE_MODEL_VERTCOL = 0x2, // mc_ - MTL_TYPE_MODEL_LIGHTMAP_VC = 0x3, // ? - MTL_TYPE_WORLD_VERTCOL = 0x4, // wc_ - MTL_TYPE_PACKED_WORLD_VERTCOL = 0x5, // ? - MTL_TYPE_QUANT_WORLD = 0x6, // ? - MTL_TYPE_QUANT_WORLD_VERTCOL = 0x7, // ? - - MTL_TYPE_COUNT, - }; - - struct MaterialTypeInfo - { - const char* materialPrefix; - const char* techniqueSetPrefix; - }; - enum MaterialConstantSource { CONST_SRC_CODE_MAYBE_DIRTY_PS_BEGIN = 0x0, diff --git a/src/ObjCommon/Game/IW4/TechsetConstantsIW4.h b/src/ObjCommon/Game/IW4/Techset/TechsetConstantsIW4.h similarity index 100% rename from src/ObjCommon/Game/IW4/TechsetConstantsIW4.h rename to src/ObjCommon/Game/IW4/Techset/TechsetConstantsIW4.h diff --git a/src/ObjCommon/Game/T6/TechsetConstantsT6.h b/src/ObjCommon/Game/T6/Techset/TechsetConstantsT6.h similarity index 100% rename from src/ObjCommon/Game/T6/TechsetConstantsT6.h rename to src/ObjCommon/Game/T6/Techset/TechsetConstantsT6.h diff --git a/src/ObjCommon/Techset/CommonTechnique.cpp b/src/ObjCommon/Techset/CommonTechnique.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/ObjCommon/Techset/CommonTechnique.h b/src/ObjCommon/Techset/CommonTechnique.h new file mode 100644 index 00000000..22259f79 --- /dev/null +++ b/src/ObjCommon/Techset/CommonTechnique.h @@ -0,0 +1,32 @@ +#pragma once + +#include +#include +#include + +namespace techset +{ + class CommonTechniqueShader + { + public: + std::string m_name; + uint32_t m_version_major; + uint32_t m_version_minor; + }; + + class CommonPass + { + public: + uint64_t m_flags; + uint32_t m_sampler_flags; + CommonTechniqueShader m_vertex_shader; + CommonTechniqueShader m_pixel_shader; + }; + + class CommonTechnique + { + public: + uint64_t m_flags; + std::vector m_passes; + }; +} // namespace techset diff --git a/src/ObjCommon/Techset/CommonTechset.cpp b/src/ObjCommon/Techset/CommonTechset.cpp new file mode 100644 index 00000000..96bc0d3b --- /dev/null +++ b/src/ObjCommon/Techset/CommonTechset.cpp @@ -0,0 +1,22 @@ +#include "CommonTechset.h" + +#include + +techset::CommonTechniqueTypeNames::CommonTechniqueTypeNames(const char** names, const size_t nameCount) + : m_names(nameCount) +{ + std::copy(names, &names[nameCount], m_names.data()); +} + +const char* techset::CommonTechniqueTypeNames::GetTechniqueTypeName(const size_t techniqueTypeIndex) const +{ + if (techniqueTypeIndex >= m_names.size()) + return nullptr; + + return m_names[techniqueTypeIndex]; +} + +size_t techset::CommonTechniqueTypeNames::GetTechniqueTypeCount() const +{ + return m_names.size(); +} diff --git a/src/ObjCommon/Techset/CommonTechset.h b/src/ObjCommon/Techset/CommonTechset.h new file mode 100644 index 00000000..5dd2c02e --- /dev/null +++ b/src/ObjCommon/Techset/CommonTechset.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include +#include + +namespace techset +{ + class CommonTechniqueTypeNames + { + public: + CommonTechniqueTypeNames(const char** names, size_t nameCount); + + [[nodiscard]] const char* GetTechniqueTypeName(size_t techniqueTypeIndex) const; + [[nodiscard]] size_t GetTechniqueTypeCount() const; + + private: + std::vector m_names; + }; + + class CommonTechset + { + public: + std::string m_name; + std::vector m_technique_names; + }; +} // namespace techset diff --git a/src/ObjCompiling/Game/IW4/Material/CompilerMaterialIW4.cpp b/src/ObjCompiling/Game/IW4/Material/CompilerMaterialIW4.cpp index 76897870..1b2aad5f 100644 --- a/src/ObjCompiling/Game/IW4/Material/CompilerMaterialIW4.cpp +++ b/src/ObjCompiling/Game/IW4/Material/CompilerMaterialIW4.cpp @@ -5,7 +5,7 @@ #include "Game/IW4/MaterialConstantsIW4.h" #include "Game/IW4/ObjConstantsIW4.h" #include "Game/IW4/Techset/CompilerTechsetIW4.h" -#include "Game/IW4/TechsetConstantsIW4.h" +#include "Game/IW4/Techset/TechsetConstantsIW4.h" #include "Gdt/AbstractGdtEntryReader.h" #include "Gdt/IGdtQueryable.h" #include "ObjLoading.h" diff --git a/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp b/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp index 7627004b..ac775a8f 100644 --- a/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp +++ b/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp @@ -3,7 +3,7 @@ #include "Game/IW4/IW4.h" #include "Game/IW4/Shader/LoaderPixelShaderIW4.h" #include "Game/IW4/Shader/LoaderVertexShaderIW4.h" -#include "Game/IW4/TechsetConstantsIW4.h" +#include "Game/IW4/Techset/TechsetConstantsIW4.h" #include "Shader/D3D9ShaderAnalyser.h" #include "Shader/ShaderCommon.h" #include "StateMap/StateMapReader.h" diff --git a/src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.cpp b/src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.cpp index 5c4144b8..9bfdaedc 100644 --- a/src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.cpp +++ b/src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.cpp @@ -1,7 +1,7 @@ #include "CompilerVertexDeclIW4.h" #include "Game/IW4/IW4.h" -#include "Game/IW4/TechsetConstantsIW4.h" +#include "Game/IW4/Techset/TechsetConstantsIW4.h" #include "Utils/Logging/Log.h" #include diff --git a/src/ObjWriting/Game/IW4/Material/MaterialDecompilingDumperIW4.cpp b/src/ObjWriting/Game/IW4/Material/MaterialDecompilingDumperIW4.cpp index 749c8d52..2a2a8e37 100644 --- a/src/ObjWriting/Game/IW4/Material/MaterialDecompilingDumperIW4.cpp +++ b/src/ObjWriting/Game/IW4/Material/MaterialDecompilingDumperIW4.cpp @@ -2,8 +2,7 @@ #include "Game/IW4/MaterialConstantsIW4.h" #include "Game/IW4/ObjConstantsIW4.h" -#include "Game/IW4/TechsetConstantsIW4.h" -#include "Utils/ClassUtils.h" +#include "Game/IW4/Techset/TechsetConstantsIW4.h" #include "Utils/Logging/Log.h" #pragma warning(push, 0) diff --git a/src/ObjWriting/Game/IW4/Techset/TechsetDumperIW4.cpp b/src/ObjWriting/Game/IW4/Techset/TechsetDumperIW4.cpp index 8714cd74..9885247e 100644 --- a/src/ObjWriting/Game/IW4/Techset/TechsetDumperIW4.cpp +++ b/src/ObjWriting/Game/IW4/Techset/TechsetDumperIW4.cpp @@ -1,9 +1,12 @@ #include "TechsetDumperIW4.h" #include "Dumping/AbstractTextDumper.h" -#include "Game/IW4/TechsetConstantsIW4.h" +#include "Game/IW4/Techset/TechsetConstantsIW4.h" #include "Pool/GlobalAssetPool.h" #include "Shader/D3D9ShaderAnalyser.h" +#include "Techset/CommonTechset.h" +#include "Techset/CommonTechsetDumper.h" +#include "Techset/TechniqueDumpingZoneState.h" #include "Techset/TechsetCommon.h" #include "Utils/Logging/Log.h" @@ -16,23 +19,8 @@ using namespace IW4; -namespace IW4 +namespace { - class TechniqueDumpingZoneState final : public IZoneAssetDumperState - { - std::set m_dumped_techniques; - - public: - bool ShouldDumpTechnique(const MaterialTechnique* technique) - { - if (m_dumped_techniques.find(technique) != m_dumped_techniques.end()) - return false; - - m_dumped_techniques.emplace(technique); - return true; - } - }; - class TechniqueFileWriter : public AbstractTextDumper { void DumpStateMap() const @@ -472,67 +460,31 @@ namespace IW4 } }; - class TechsetFileWriter : public AbstractTextDumper + techset::CommonTechset ConvertToCommonTechset(const MaterialTechniqueSet& techset) { - bool m_last_write_was_value; + std::vector techniqueNames(std::extent_v); - public: - explicit TechsetFileWriter(std::ostream& stream) - : AbstractTextDumper(stream), - m_last_write_was_value(false) + for (auto techniqueIndex = 0u; techniqueIndex < std::extent_v; techniqueIndex++) { + const auto* technique = techset.techniques[techniqueIndex]; + if (technique && technique->name) + techniqueNames[techniqueIndex] = technique->name; } - void WriteTechniqueType(const size_t techniqueIndex) - { - assert(techniqueIndex < std::extent_v); + return techset::CommonTechset{ + .m_name = techset.name, + .m_technique_names = std::move(techniqueNames), + }; + } - if (m_last_write_was_value) - { - m_stream << "\n"; - m_last_write_was_value = false; - } - m_stream << '"' << techniqueTypeNames[techniqueIndex] << "\":\n"; - } + void DumpTechset(const AssetDumpingContext& context, const MaterialTechniqueSet& techset) + { + static techset::CommonTechniqueTypeNames commonNames(techniqueTypeNames, std::extent_v); + const auto commonTechset = ConvertToCommonTechset(techset); - void WriteTechniqueValue(const char* value) - { - m_last_write_was_value = true; - - IncIndent(); - Indent(); - m_stream << value << ";\n"; - DecIndent(); - } - - void DumpTechset(const MaterialTechniqueSet* techset) - { - std::vector dumpedTechniques(std::extent_v); - - for (auto techniqueIndex = 0u; techniqueIndex < std::extent_v; techniqueIndex++) - { - const auto* technique = techset->techniques[techniqueIndex]; - if (technique == nullptr || dumpedTechniques[techniqueIndex]) - continue; - - dumpedTechniques[techniqueIndex] = true; - WriteTechniqueType(techniqueIndex); - - for (auto nextTechniqueIndex = techniqueIndex + 1; nextTechniqueIndex < std::extent_v; - nextTechniqueIndex++) - { - if (techset->techniques[nextTechniqueIndex] != technique) - continue; - - dumpedTechniques[nextTechniqueIndex] = true; - WriteTechniqueType(nextTechniqueIndex); - } - - WriteTechniqueValue(technique->name); - } - } - }; -} // namespace IW4 + techset::DumpCommonTechset(commonNames, context, commonTechset); + } +} // namespace namespace techset { @@ -543,18 +495,11 @@ namespace techset void DumperIW4::DumpAsset(AssetDumpingContext& context, const XAssetInfo& asset) { - const auto* techset = asset.Asset(); - - const auto techsetFile = context.OpenAssetFile(GetFileNameForTechsetName(techset->name)); - - if (techsetFile) - { - TechsetFileWriter writer(*techsetFile); - writer.DumpTechset(techset); - } + const auto* techniqueSet = asset.Asset(); + DumpTechset(context, *techniqueSet); auto* techniqueState = context.GetZoneAssetDumperState(); - for (const auto* technique : techset->techniques) + for (const auto* technique : techniqueSet->techniques) { if (technique && techniqueState->ShouldDumpTechnique(technique)) { diff --git a/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp b/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp index 157b17ea..b49c6b74 100644 --- a/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp +++ b/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp @@ -1,6 +1,10 @@ #include "TechsetDumperT6.h" +#include "Game/T6/Techset/TechsetConstantsT6.h" #include "Shader/ShaderCommon.h" +#include "Techset/CommonTechniqueDumper.h" +#include "Techset/CommonTechsetDumper.h" +#include "Techset/TechniqueDumpingZoneState.h" #include #include @@ -73,21 +77,12 @@ namespace shaderFile->write(vertexShader.prog.loadDef.program, vertexShader.prog.loadDef.programSize); } -} // namespace -namespace techset -{ - DumperT6::DumperT6(const AssetPool& pool) - : AbstractAssetDumper(pool) + void DumpShaders(AssetDumpingContext& context, const MaterialTechniqueSet& techset) { - } - - void DumperT6::DumpAsset(AssetDumpingContext& context, const XAssetInfo& asset) - { - const auto* techniqueSet = asset.Asset(); auto* shaderState = context.GetZoneAssetDumperState(); - for (const auto* technique : techniqueSet->techniques) + for (const auto* technique : techset.techniques) { if (!technique || !shaderState->ShouldDumpTechnique(technique)) continue; @@ -104,4 +99,76 @@ namespace techset } } } + + techset::CommonTechnique ConvertToCommonTechnique(const MaterialTechnique& technique) + { + std::vector techniqueNames(std::extent_v); + + for (auto techniqueIndex = 0u; techniqueIndex < std::extent_v; techniqueIndex++) + { + const auto* technique = techset.techniques[techniqueIndex]; + if (technique && technique->name) + techniqueNames[techniqueIndex] = technique->name; + } + + return techset::CommonTechset{ + .m_name = techset.name, + .m_technique_names = std::move(techniqueNames), + }; + } + + void DumpTechniques(AssetDumpingContext& context, const MaterialTechniqueSet& techset) + { + auto* techniqueState = context.GetZoneAssetDumperState(); + for (const auto* technique : techset.techniques) + { + if (technique && techniqueState->ShouldDumpTechnique(technique)) + { + const auto commonTechnique = ConvertToCommonTechnique(*technique); + + techset::DumpCommonTechnique(context, commonTechnique); + } + } + } + + techset::CommonTechset ConvertToCommonTechset(const MaterialTechniqueSet& techset) + { + std::vector techniqueNames(std::extent_v); + + for (auto techniqueIndex = 0u; techniqueIndex < std::extent_v; techniqueIndex++) + { + const auto* technique = techset.techniques[techniqueIndex]; + if (technique && technique->name) + techniqueNames[techniqueIndex] = technique->name; + } + + return techset::CommonTechset{ + .m_name = techset.name, + .m_technique_names = std::move(techniqueNames), + }; + } + + void DumpTechset(const AssetDumpingContext& context, const MaterialTechniqueSet& techset) + { + static techset::CommonTechniqueTypeNames commonNames(techniqueTypeNames, std::extent_v); + const auto commonTechset = ConvertToCommonTechset(techset); + + techset::DumpCommonTechset(commonNames, context, commonTechset); + } +} // namespace + +namespace techset +{ + DumperT6::DumperT6(const AssetPool& pool) + : AbstractAssetDumper(pool) + { + } + + void DumperT6::DumpAsset(AssetDumpingContext& context, const XAssetInfo& asset) + { + const auto* techniqueSet = asset.Asset(); + DumpTechset(context, *techniqueSet); + DumpTechniques(context, *techniqueSet); + DumpShaders(context, *techniqueSet); + } } // namespace techset diff --git a/src/ObjWriting/Techset/CommonTechniqueDumper.cpp b/src/ObjWriting/Techset/CommonTechniqueDumper.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/ObjWriting/Techset/CommonTechniqueDumper.h b/src/ObjWriting/Techset/CommonTechniqueDumper.h new file mode 100644 index 00000000..168c27b7 --- /dev/null +++ b/src/ObjWriting/Techset/CommonTechniqueDumper.h @@ -0,0 +1,9 @@ +#pragma once + +#include "Dumping/AssetDumpingContext.h" +#include "Techset/CommonTechset.h" + +namespace techset +{ + void DumpCommonTechnique(const AssetDumpingContext& context, const CommonTechset& techset); +} // namespace techset diff --git a/src/ObjWriting/Techset/CommonTechsetDumper.cpp b/src/ObjWriting/Techset/CommonTechsetDumper.cpp new file mode 100644 index 00000000..d2c9b9db --- /dev/null +++ b/src/ObjWriting/Techset/CommonTechsetDumper.cpp @@ -0,0 +1,92 @@ +#include "CommonTechsetDumper.h" + +#include "Dumping/AbstractTextDumper.h" +#include "Game/IW3/Material/MaterialConstantZoneStateIW3.h" +#include "Techset/TechsetCommon.h" + +#include + +using namespace techset; + +namespace +{ + class TechsetFileWriter : public AbstractTextDumper + { + public: + TechsetFileWriter(const CommonTechniqueTypeNames& techniqueTypeNames, std::ostream& stream) + : AbstractTextDumper(stream), + m_last_write_was_value(false), + m_technique_type_names(techniqueTypeNames) + { + } + + void DumpTechset(const CommonTechset& techset) + { + const auto techniqueCount = m_technique_type_names.GetTechniqueTypeCount(); + assert(techset.m_technique_names.size() == techniqueCount); + + std::vector dumpedTechniques(techniqueCount); + + for (auto techniqueIndex = 0u; techniqueIndex < techniqueCount; techniqueIndex++) + { + const auto& technique = techset.m_technique_names[techniqueIndex]; + if (technique.empty() || dumpedTechniques[techniqueIndex]) + continue; + + dumpedTechniques[techniqueIndex] = true; + WriteTechniqueType(techniqueIndex); + + for (auto nextTechniqueIndex = techniqueIndex + 1; nextTechniqueIndex < std::extent_v; + nextTechniqueIndex++) + { + if (techset.m_technique_names[nextTechniqueIndex] != technique) + continue; + + dumpedTechniques[nextTechniqueIndex] = true; + WriteTechniqueType(nextTechniqueIndex); + } + + WriteTechniqueValue(technique); + } + } + + private: + void WriteTechniqueType(const size_t techniqueIndex) + { + if (m_last_write_was_value) + { + m_stream << "\n"; + m_last_write_was_value = false; + } + + m_stream << '"' << m_technique_type_names.GetTechniqueTypeName(techniqueIndex) << "\":\n"; + } + + void WriteTechniqueValue(const std::string& value) + { + m_last_write_was_value = true; + + IncIndent(); + Indent(); + m_stream << value << ";\n"; + DecIndent(); + } + + bool m_last_write_was_value; + const CommonTechniqueTypeNames& m_technique_type_names; + }; +} // namespace + +namespace techset +{ + void DumpCommonTechset(const CommonTechniqueTypeNames& techniqueTypeNames, const AssetDumpingContext& context, const CommonTechset& techset) + { + const auto techsetFile = context.OpenAssetFile(GetFileNameForTechsetName(techset.m_name)); + + if (techsetFile) + { + TechsetFileWriter writer(techniqueTypeNames, *techsetFile); + writer.DumpTechset(techset); + } + } +} // namespace techset diff --git a/src/ObjWriting/Techset/CommonTechsetDumper.h b/src/ObjWriting/Techset/CommonTechsetDumper.h new file mode 100644 index 00000000..08d886f4 --- /dev/null +++ b/src/ObjWriting/Techset/CommonTechsetDumper.h @@ -0,0 +1,9 @@ +#pragma once + +#include "Dumping/AssetDumpingContext.h" +#include "Techset/CommonTechset.h" + +namespace techset +{ + void DumpCommonTechset(const CommonTechniqueTypeNames& techniqueTypeNames, const AssetDumpingContext& context, const CommonTechset& techset); +} // namespace techset diff --git a/src/ObjWriting/Techset/TechniqueDumpingZoneState.cpp b/src/ObjWriting/Techset/TechniqueDumpingZoneState.cpp new file mode 100644 index 00000000..7ca2e43d --- /dev/null +++ b/src/ObjWriting/Techset/TechniqueDumpingZoneState.cpp @@ -0,0 +1,13 @@ +#include "TechniqueDumpingZoneState.h" + +namespace techset +{ + bool TechniqueDumpingZoneState::ShouldDumpTechnique(const void* technique) + { + if (m_dumped_techniques.find(technique) != m_dumped_techniques.end()) + return false; + + m_dumped_techniques.emplace(technique); + return true; + } +} // namespace techset diff --git a/src/ObjWriting/Techset/TechniqueDumpingZoneState.h b/src/ObjWriting/Techset/TechniqueDumpingZoneState.h new file mode 100644 index 00000000..06e3aad1 --- /dev/null +++ b/src/ObjWriting/Techset/TechniqueDumpingZoneState.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Dumping/IZoneAssetDumperState.h" + +#include + +namespace techset +{ + class TechniqueDumpingZoneState final : public IZoneAssetDumperState + { + public: + bool ShouldDumpTechnique(const void* technique); + + private: + std::unordered_set m_dumped_techniques; + }; +} // namespace techset From 9b526adaede30558a7f022ed15b655ba84fb52e7 Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Thu, 13 Nov 2025 22:44:09 +0000 Subject: [PATCH 2/5] feat: dump material techniques for T6 --- src/ObjCommon/Shader/D3D11ShaderAnalyser.cpp | 21 +-- src/ObjCommon/Shader/D3D11ShaderAnalyser.h | 13 +- src/ObjCommon/Shader/D3D9ShaderAnalyser.h | 9 +- src/ObjCommon/Techset/CommonTechnique.h | 13 +- .../Game/T6/Techset/TechsetDumperT6.cpp | 50 ++++-- .../Techset/CommonTechniqueDumper.cpp | 143 ++++++++++++++++++ .../Techset/CommonTechniqueDumper.h | 4 +- .../Techset/CommonTechsetDumper.cpp | 4 +- 8 files changed, 221 insertions(+), 36 deletions(-) diff --git a/src/ObjCommon/Shader/D3D11ShaderAnalyser.cpp b/src/ObjCommon/Shader/D3D11ShaderAnalyser.cpp index 4f4225e8..f866236f 100644 --- a/src/ObjCommon/Shader/D3D11ShaderAnalyser.cpp +++ b/src/ObjCommon/Shader/D3D11ShaderAnalyser.cpp @@ -32,14 +32,17 @@ namespace d3d11 m_flags(0u) { } +} // namespace d3d11 - static constexpr auto TAG_RDEF = FileUtils::MakeMagic32('R', 'D', 'E', 'F'); - static constexpr auto TAG_SHDR = FileUtils::MakeMagic32('S', 'H', 'D', 'R'); +namespace +{ + constexpr auto TAG_RDEF = FileUtils::MakeMagic32('R', 'D', 'E', 'F'); + constexpr auto TAG_SHDR = FileUtils::MakeMagic32('S', 'H', 'D', 'R'); - static constexpr auto VERSION_5_0 = 0x500; - static constexpr auto VERSION_5_1 = 0x501; - static constexpr auto TARGET_VERSION_MASK = 0xFFFF; - static constexpr auto CHUNK_TABLE_OFFSET = 28u; + constexpr auto VERSION_5_0 = 0x500; + constexpr auto VERSION_5_1 = 0x501; + constexpr auto TARGET_VERSION_MASK = 0xFFFF; + constexpr auto CHUNK_TABLE_OFFSET = 28u; struct FileRdefHeader { @@ -669,16 +672,16 @@ namespace d3d11 return true; } -} // namespace d3d11 +} // namespace -std::unique_ptr ShaderAnalyser::GetShaderInfo(const uint8_t* shader, const size_t shaderSize) +std::unique_ptr ShaderAnalyser::GetShaderInfo(const void* shader, const size_t shaderSize) { if (shader == nullptr || shaderSize == 0) return nullptr; auto shaderInfo = std::make_unique(); - if (!PopulateShaderInfoFromBytes(*shaderInfo, shader, shaderSize)) + if (!PopulateShaderInfoFromBytes(*shaderInfo, static_cast(shader), shaderSize)) return nullptr; return shaderInfo; diff --git a/src/ObjCommon/Shader/D3D11ShaderAnalyser.h b/src/ObjCommon/Shader/D3D11ShaderAnalyser.h index 59f9f9aa..e544fcea 100644 --- a/src/ObjCommon/Shader/D3D11ShaderAnalyser.h +++ b/src/ObjCommon/Shader/D3D11ShaderAnalyser.h @@ -1,12 +1,13 @@ #pragma once +#include #include #include #include namespace d3d11 { - enum class ShaderType + enum class ShaderType : std::uint8_t { UNKNOWN, PIXEL_SHADER, @@ -33,7 +34,7 @@ namespace d3d11 unsigned m_flags; }; - enum class ConstantBufferType + enum class ConstantBufferType : std::uint8_t { UNKNOWN, CBUFFER, @@ -59,7 +60,7 @@ namespace d3d11 std::vector m_variables; }; - enum class BoundResourceType + enum class BoundResourceType : std::uint8_t { UNKNOWN, CBUFFER, @@ -68,7 +69,7 @@ namespace d3d11 SAMPLER }; - enum class BoundResourceReturnType + enum class BoundResourceReturnType : std::uint8_t { UNKNOWN, UNORM, @@ -81,7 +82,7 @@ namespace d3d11 CONTINUED, }; - enum class BoundResourceDimension + enum class BoundResourceDimension : std::uint8_t { UNKNOWN, BUFFER, @@ -131,6 +132,6 @@ namespace d3d11 class ShaderAnalyser { public: - static std::unique_ptr GetShaderInfo(const uint8_t* shader, size_t shaderSize); + static std::unique_ptr GetShaderInfo(const void* shader, size_t shaderSize); }; } // namespace d3d11 diff --git a/src/ObjCommon/Shader/D3D9ShaderAnalyser.h b/src/ObjCommon/Shader/D3D9ShaderAnalyser.h index 7e186c8d..32f5c058 100644 --- a/src/ObjCommon/Shader/D3D9ShaderAnalyser.h +++ b/src/ObjCommon/Shader/D3D9ShaderAnalyser.h @@ -1,12 +1,13 @@ #pragma once +#include #include #include #include namespace d3d9 { - enum class ShaderType + enum class ShaderType : std::uint8_t { UNKNOWN, PIXEL_SHADER, @@ -14,7 +15,7 @@ namespace d3d9 }; // https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3dxregister-set - enum class RegisterSet + enum class RegisterSet : std::uint8_t { BOOL, INT_4, @@ -26,7 +27,7 @@ namespace d3d9 }; // https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3dxparameter-class - enum class ParameterClass + enum class ParameterClass : std::uint8_t { SCALAR, VECTOR, @@ -40,7 +41,7 @@ namespace d3d9 }; // https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3dxparameter-type - enum class ParameterType + enum class ParameterType : std::uint8_t { VOID, BOOL, diff --git a/src/ObjCommon/Techset/CommonTechnique.h b/src/ObjCommon/Techset/CommonTechnique.h index 22259f79..5f5a4835 100644 --- a/src/ObjCommon/Techset/CommonTechnique.h +++ b/src/ObjCommon/Techset/CommonTechnique.h @@ -10,15 +10,21 @@ namespace techset { public: std::string m_name; - uint32_t m_version_major; - uint32_t m_version_minor; + const void* m_shader_bin; + size_t m_shader_bin_size; + }; + + enum class DxVersion : std::uint8_t + { + DX9, + DX11 }; class CommonPass { public: - uint64_t m_flags; uint32_t m_sampler_flags; + DxVersion m_dx_version; CommonTechniqueShader m_vertex_shader; CommonTechniqueShader m_pixel_shader; }; @@ -26,6 +32,7 @@ namespace techset class CommonTechnique { public: + std::string m_name; uint64_t m_flags; std::vector m_passes; }; diff --git a/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp b/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp index b49c6b74..e3327ec7 100644 --- a/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp +++ b/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp @@ -6,7 +6,6 @@ #include "Techset/CommonTechsetDumper.h" #include "Techset/TechniqueDumpingZoneState.h" -#include #include using namespace T6; @@ -102,18 +101,51 @@ namespace techset::CommonTechnique ConvertToCommonTechnique(const MaterialTechnique& technique) { - std::vector techniqueNames(std::extent_v); + std::vector passes; - for (auto techniqueIndex = 0u; techniqueIndex < std::extent_v; techniqueIndex++) + for (auto passIndex = 0u; passIndex < technique.passCount; passIndex++) { - const auto* technique = techset.techniques[techniqueIndex]; - if (technique && technique->name) - techniqueNames[techniqueIndex] = technique->name; + const auto& pass = technique.passArray[passIndex]; + + techset::CommonTechniqueShader vertexShader{}; + techset::CommonTechniqueShader pixelShader{}; + + if (pass.vertexShader) + { + if (pass.vertexShader->name) + vertexShader.m_name = pass.vertexShader->name; + + if (pass.vertexShader->prog.loadDef.program) + { + vertexShader.m_shader_bin = pass.vertexShader->prog.loadDef.program; + vertexShader.m_shader_bin_size = pass.vertexShader->prog.loadDef.programSize * sizeof(uint32_t); + } + } + + if (pass.pixelShader) + { + if (pass.pixelShader->name) + pixelShader.m_name = pass.pixelShader->name; + + if (pass.pixelShader->prog.loadDef.program) + { + pixelShader.m_shader_bin = pass.pixelShader->prog.loadDef.program; + pixelShader.m_shader_bin_size = pass.pixelShader->prog.loadDef.programSize * sizeof(uint32_t); + } + } + + passes.emplace_back(techset::CommonPass{ + .m_sampler_flags = pass.customSamplerFlags, + .m_dx_version = techset::DxVersion::DX11, + .m_vertex_shader = vertexShader, + .m_pixel_shader = pixelShader, + }); } - return techset::CommonTechset{ - .m_name = techset.name, - .m_technique_names = std::move(techniqueNames), + return techset::CommonTechnique{ + .m_name = technique.name ? technique.name : std::string(), + .m_flags = technique.flags, + .m_passes = std::move(passes), }; } diff --git a/src/ObjWriting/Techset/CommonTechniqueDumper.cpp b/src/ObjWriting/Techset/CommonTechniqueDumper.cpp index e69de29b..9e497da5 100644 --- a/src/ObjWriting/Techset/CommonTechniqueDumper.cpp +++ b/src/ObjWriting/Techset/CommonTechniqueDumper.cpp @@ -0,0 +1,143 @@ +#include "CommonTechniqueDumper.h" + +#include "Dumping/AbstractTextDumper.h" +#include "Shader/D3D11ShaderAnalyser.h" +#include "Shader/D3D9ShaderAnalyser.h" +#include "Techset/TechsetCommon.h" + +#include +#include + +using namespace techset; + +namespace +{ + enum class TechniqueShaderType : std::uint8_t + { + VERTEX_SHADER, + PIXEL_SHADER + }; + + class TechniqueFileWriter : public AbstractTextDumper + { + public: + explicit TechniqueFileWriter(std::ostream& stream) + : AbstractTextDumper(stream) + { + } + + void DumpTechnique(const CommonTechnique& technique) + { +#ifdef TECHSET_DEBUG + if (technique.m_flags) + { + for (auto i = 0u; i < sizeof(CommonTechnique::m_flags) * 8u; i++) + { + const auto mask = 1ui64 << i; + if (technique.m_flags & mask) + { + Indent(); + m_stream << std::format("// TECHNIQUE FLAGS: 0x{:x}\n", mask); + } + } + } +#endif + + for (const auto& pass : technique.m_passes) + DumpPass(pass); + } + + private: + void DumpPass(const CommonPass& pass) + { + m_stream << "{\n"; + IncIndent(); + +#ifdef TECHSET_DEBUG + for (auto i = 0u; i < sizeof(CommonPass::m_sampler_flags) * 8u; i++) + { + const auto mask = 1ui64 << i; + if (pass.m_sampler_flags & mask) + { + Indent(); + m_stream << std::format("// CUSTOM SAMPLER FLAGS: 0x{:x}\n", mask); + } + } +#endif + + DumpStateMap(); + DumpShader(pass, pass.m_vertex_shader, TechniqueShaderType::VERTEX_SHADER); + DumpShader(pass, pass.m_pixel_shader, TechniqueShaderType::PIXEL_SHADER); + // DumpVertexDecl(pass); + + DecIndent(); + m_stream << "}\n"; + } + + void DumpStateMap() const + { + Indent(); + // TODO: Actual statemap: Maybe find all materials using this techset and try to make out rules + // for the flags based on the statebitstable + m_stream << "stateMap \"passthrough\"; // TODO\n"; + } + + void DumpShader(const CommonPass& pass, const CommonTechniqueShader& shader, const TechniqueShaderType shaderType) const + { + if (!shader.m_shader_bin) + { + if (!shader.m_name.empty()) + m_stream << std::format("// Cannot dump shader {} as its data is not loaded\n", shader.m_name); + + return; + } + + unsigned versionMajor, versionMinor; + if (pass.m_dx_version == DxVersion::DX9) + { + const auto shaderInfo = d3d9::ShaderAnalyser::GetShaderInfo(shader.m_shader_bin, shader.m_shader_bin_size); + assert(shaderInfo); + if (!shaderInfo) + return; + + versionMajor = shaderInfo->m_version_major; + versionMinor = shaderInfo->m_version_minor; + } + else + { + assert(pass.m_dx_version == DxVersion::DX11); + const auto shaderInfo = d3d11::ShaderAnalyser::GetShaderInfo(shader.m_shader_bin, shader.m_shader_bin_size); + assert(shaderInfo); + if (!shaderInfo) + return; + + versionMajor = shaderInfo->m_version_major; + versionMinor = shaderInfo->m_version_minor; + } + + const auto shaderTypeName = shaderType == TechniqueShaderType::VERTEX_SHADER ? "vertexShader" : "pixelShader"; + + m_stream << "\n"; + Indent(); + m_stream << std::format("{} {}.{} \"{}\"\n", shaderTypeName, versionMajor, versionMinor, shader.m_name); + Indent(); + m_stream << "{\n"; + + Indent(); + m_stream << "}\n"; + } + }; +} // namespace + +namespace techset +{ + void DumpCommonTechnique(const AssetDumpingContext& context, const CommonTechnique& technique) + { + const auto techniqueFile = context.OpenAssetFile(GetFileNameForTechniqueName(technique.m_name)); + if (techniqueFile) + { + TechniqueFileWriter writer(*techniqueFile); + writer.DumpTechnique(technique); + } + } +} // namespace techset diff --git a/src/ObjWriting/Techset/CommonTechniqueDumper.h b/src/ObjWriting/Techset/CommonTechniqueDumper.h index 168c27b7..d541414a 100644 --- a/src/ObjWriting/Techset/CommonTechniqueDumper.h +++ b/src/ObjWriting/Techset/CommonTechniqueDumper.h @@ -1,9 +1,9 @@ #pragma once #include "Dumping/AssetDumpingContext.h" -#include "Techset/CommonTechset.h" +#include "Techset/CommonTechnique.h" namespace techset { - void DumpCommonTechnique(const AssetDumpingContext& context, const CommonTechset& techset); + void DumpCommonTechnique(const AssetDumpingContext& context, const CommonTechnique& technique); } // namespace techset diff --git a/src/ObjWriting/Techset/CommonTechsetDumper.cpp b/src/ObjWriting/Techset/CommonTechsetDumper.cpp index d2c9b9db..8448cc4b 100644 --- a/src/ObjWriting/Techset/CommonTechsetDumper.cpp +++ b/src/ObjWriting/Techset/CommonTechsetDumper.cpp @@ -1,7 +1,6 @@ #include "CommonTechsetDumper.h" #include "Dumping/AbstractTextDumper.h" -#include "Game/IW3/Material/MaterialConstantZoneStateIW3.h" #include "Techset/TechsetCommon.h" #include @@ -36,8 +35,7 @@ namespace dumpedTechniques[techniqueIndex] = true; WriteTechniqueType(techniqueIndex); - for (auto nextTechniqueIndex = techniqueIndex + 1; nextTechniqueIndex < std::extent_v; - nextTechniqueIndex++) + for (auto nextTechniqueIndex = techniqueIndex + 1; nextTechniqueIndex < techniqueCount; nextTechniqueIndex++) { if (techset.m_technique_names[nextTechniqueIndex] != technique) continue; From 930b116ac09bdd46c21530fed3adc6a98ae8b476 Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Sat, 15 Nov 2025 18:57:39 +0000 Subject: [PATCH 3/5] feat: add vertex declaration to t6 techset dumps --- .../Game/T6/Techset/TechsetConstantsT6.h | 197 +++++++++++++----- src/ObjCommon/Techset/CommonTechnique.cpp | 55 +++++ src/ObjCommon/Techset/CommonTechnique.h | 49 +++++ .../Game/T6/Techset/TechsetDumperT6.cpp | 28 ++- .../Techset/CommonTechniqueDumper.cpp | 38 +++- .../Techset/CommonTechniqueDumper.h | 2 +- 6 files changed, 309 insertions(+), 60 deletions(-) diff --git a/src/ObjCommon/Game/T6/Techset/TechsetConstantsT6.h b/src/ObjCommon/Game/T6/Techset/TechsetConstantsT6.h index 48f3be31..72237e82 100644 --- a/src/ObjCommon/Game/T6/Techset/TechsetConstantsT6.h +++ b/src/ObjCommon/Game/T6/Techset/TechsetConstantsT6.h @@ -1,7 +1,7 @@ #pragma once -#include "Game/T6/CommonT6.h" #include "Game/T6/T6.h" +#include "Techset/CommonTechnique.h" namespace T6 { @@ -45,57 +45,158 @@ namespace T6 }; static_assert(std::extent_v == TECHNIQUE_COUNT); - static const char* materialStreamDestinationNames[]{ - "position", "normal", "color[0]", "color[1]", "depth", "texcoord[0]", "texcoord[1]", - "texcoord[2]", "texcoord[3]", "texcoord[4]", "texcoord[5]", "texcoord[6]", "texcoord[7]", "texcoord[8]", - "texcoord[9]", "texcoord[10]", "texcoord[11]", "texcoord[12]", "texcoord[13]", "blendWeight", + static techset::CommonStreamRoutingSourceInfo streamRoutingSources[]{ + { + .name = "position", + .abbreviation = "p", + .optional = false, + }, + { + .name = "color", + .abbreviation = "c", + .optional = false, + }, + { + .name = "texcoord[0]", + .abbreviation = "t0", + .optional = false, + }, + { + .name = "normal", + .abbreviation = "n", + .optional = false, + }, + { + .name = "tangent", + .abbreviation = "t", + .optional = false, + }, + { + .name = "texcoord[1]", + .abbreviation = "t1", + .optional = false, + }, + { + .name = "texcoord[2]", + .abbreviation = "t2", + .optional = true, + }, + { + .name = "texcoord[3]", + .abbreviation = "t3", + .optional = true, + }, + { + .name = "normalTransform[0]", + .abbreviation = "n0", + .optional = true, + }, + { + .name = "normalTransform[1]", + .abbreviation = "n1", + .optional = true, + }, + { + .name = "blendWeight", + .abbreviation = "b", + .optional = true, + }, }; - static_assert(std::extent_v == STREAM_DST_COUNT); + static_assert(std::extent_v == STREAM_SRC_COUNT); - static const char* materialStreamDestinationAbbreviation[]{ - "p", "n", "c0", "c1", "d", "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9", "t10", "t11", "t12", "t13", "b", + static techset::CommonStreamRoutingDestinationInfo streamRoutingDestinations[]{ + { + .name = "position", + .abbreviation = "p", + }, + { + .name = "normal", + .abbreviation = "n", + }, + { + .name = "color[0]", + .abbreviation = "c0", + }, + { + .name = "color[1]", + .abbreviation = "c1", + }, + { + .name = "depth", + .abbreviation = "d", + }, + { + .name = "texcoord[0]", + .abbreviation = "t0", + }, + { + .name = "texcoord[1]", + .abbreviation = "t1", + }, + { + .name = "texcoord[2]", + .abbreviation = "t2", + }, + { + .name = "texcoord[3]", + .abbreviation = "t3", + }, + { + .name = "texcoord[4]", + .abbreviation = "t4", + }, + { + .name = "texcoord[5]", + .abbreviation = "t5", + }, + { + .name = "texcoord[6]", + .abbreviation = "t6", + }, + { + .name = "texcoord[7]", + .abbreviation = "t7", + }, + { + .name = "texcoord[8]", + .abbreviation = "t8", + }, + { + .name = "texcoord[9]", + .abbreviation = "t9", + }, + { + .name = "texcoord[10]", + .abbreviation = "t10", + }, + { + .name = "texcoord[11]", + .abbreviation = "t11", + }, + { + .name = "texcoord[12]", + .abbreviation = "t12", + }, + { + .name = "texcoord[13]", + .abbreviation = "t13", + }, + { + .name = "blendWeight", + .abbreviation = "b", + }, }; - static_assert(std::extent_v == STREAM_DST_COUNT); - - static const char* materialStreamSourceNames[]{ - "position", - "color", - "texcoord[0]", - "normal", - "tangent", - "texcoord[1]", - "texcoord[2]", - "texcoord[3]", - "normalTransform[0]", - "normalTransform[1]", - "blendWeight", - }; - static_assert(std::extent_v == STREAM_SRC_COUNT); - - static const char* materialStreamSourceAbbreviation[]{ - "p", - "c", - "t0", - "n", - "t", - "t1", - "t2", - "t3", - "n0", - "n1", - "b", - }; - static_assert(std::extent_v == STREAM_SRC_COUNT); + static_assert(std::extent_v == STREAM_DST_COUNT); inline MaterialTypeInfo g_materialTypeInfo[]{ - {"", "" }, - {"m/", "m_" }, - {"mc/", "mc_"}, - {"?", "?" }, - {"wc/", "wc_"}, - {"?", "?" }, - {"?", "?" }, - {"?", "?" }, - }; // TODO: Fill this + {"", "" }, + {"m/", "m_" }, + {"mc/", "mc_" }, + {"mlv/", "mlv_"}, + {"wc/", "wc_" }, + {"wpc/", "wpc_"}, + {"wq/", "wq_" }, + {"wqc/", "wqc_"}, + }; static_assert(std::extent_v == MTL_TYPE_COUNT); } // namespace T6 diff --git a/src/ObjCommon/Techset/CommonTechnique.cpp b/src/ObjCommon/Techset/CommonTechnique.cpp index e69de29b..135e7a35 100644 --- a/src/ObjCommon/Techset/CommonTechnique.cpp +++ b/src/ObjCommon/Techset/CommonTechnique.cpp @@ -0,0 +1,55 @@ +#include "CommonTechnique.h" + +namespace techset +{ + CommonStreamRoutingInfos::CommonStreamRoutingInfos(const CommonStreamRoutingSourceInfo* sourceInfos, + const size_t sourceCount, + const CommonStreamRoutingDestinationInfo* destinationNames, + const size_t destinationCount) + : m_sources(sourceCount), + m_destinations(destinationCount) + { + std::copy(sourceInfos, &sourceInfos[sourceCount], m_sources.data()); + std::copy(destinationNames, &destinationNames[destinationCount], m_destinations.data()); + } + + const char* CommonStreamRoutingInfos::GetSourceName(const CommonStreamSource source) const + { + if (source >= m_sources.size()) + return nullptr; + + return m_sources[source].name; + } + + const char* CommonStreamRoutingInfos::GetSourceAbbreviation(const CommonStreamSource source) const + { + if (source >= m_sources.size()) + return nullptr; + + return m_sources[source].abbreviation; + } + + bool CommonStreamRoutingInfos::IsSourceOptional(const CommonStreamSource source) const + { + if (source >= m_sources.size()) + return false; + + return m_sources[source].optional; + } + + const char* CommonStreamRoutingInfos::GetDestinationName(const CommonStreamDestination destination) const + { + if (destination >= m_destinations.size()) + return nullptr; + + return m_destinations[destination].name; + } + + const char* CommonStreamRoutingInfos::GetDestinationAbbreviation(const CommonStreamDestination destination) const + { + if (destination >= m_destinations.size()) + return nullptr; + + return m_destinations[destination].abbreviation; + } +} // namespace techset diff --git a/src/ObjCommon/Techset/CommonTechnique.h b/src/ObjCommon/Techset/CommonTechnique.h index 5f5a4835..928f1e24 100644 --- a/src/ObjCommon/Techset/CommonTechnique.h +++ b/src/ObjCommon/Techset/CommonTechnique.h @@ -6,6 +6,54 @@ namespace techset { + struct CommonStreamRoutingSourceInfo + { + const char* name; + const char* abbreviation; + bool optional; + }; + + struct CommonStreamRoutingDestinationInfo + { + const char* name; + const char* abbreviation; + }; + + typedef std::uint8_t CommonStreamSource; + typedef std::uint8_t CommonStreamDestination; + + class CommonStreamRoutingInfos + { + public: + CommonStreamRoutingInfos(const CommonStreamRoutingSourceInfo* sourceInfos, + size_t sourceCount, + const CommonStreamRoutingDestinationInfo* destinationNames, + size_t destinationCount); + + [[nodiscard]] const char* GetSourceName(CommonStreamSource source) const; + [[nodiscard]] const char* GetSourceAbbreviation(CommonStreamSource source) const; + [[nodiscard]] bool IsSourceOptional(CommonStreamSource source) const; + [[nodiscard]] const char* GetDestinationName(CommonStreamDestination destination) const; + [[nodiscard]] const char* GetDestinationAbbreviation(CommonStreamDestination destination) const; + + private: + std::vector m_sources; + std::vector m_destinations; + }; + + class CommonStreamRouting + { + public: + CommonStreamSource m_source; + CommonStreamDestination m_destination; + }; + + class CommonVertexDeclaration + { + public: + std::vector m_routing; + }; + class CommonTechniqueShader { public: @@ -27,6 +75,7 @@ namespace techset DxVersion m_dx_version; CommonTechniqueShader m_vertex_shader; CommonTechniqueShader m_pixel_shader; + CommonVertexDeclaration m_vertex_declaration; }; class CommonTechnique diff --git a/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp b/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp index e3327ec7..e2191c59 100644 --- a/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp +++ b/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp @@ -99,6 +99,28 @@ namespace } } + techset::CommonVertexDeclaration ConvertToCommonVertexDeclaration(const MaterialVertexDeclaration* vertexDecl) + { + std::vector commonRouting; + + if (vertexDecl) + { + const auto streamCount = std::min(static_cast(vertexDecl->streamCount), std::extent_v); + for (auto streamIndex = 0u; streamIndex < streamCount; streamIndex++) + { + const auto& routing = vertexDecl->routing.data[streamIndex]; + commonRouting.emplace_back(techset::CommonStreamRouting{ + .m_source = static_cast(routing.source), + .m_destination = static_cast(routing.dest), + }); + } + } + + return techset::CommonVertexDeclaration{ + .m_routing = std::move(commonRouting), + }; + } + techset::CommonTechnique ConvertToCommonTechnique(const MaterialTechnique& technique) { std::vector passes; @@ -139,6 +161,7 @@ namespace .m_dx_version = techset::DxVersion::DX11, .m_vertex_shader = vertexShader, .m_pixel_shader = pixelShader, + .m_vertex_declaration = ConvertToCommonVertexDeclaration(pass.vertexDecl), }); } @@ -151,6 +174,9 @@ namespace void DumpTechniques(AssetDumpingContext& context, const MaterialTechniqueSet& techset) { + static techset::CommonStreamRoutingInfos routingInfos( + streamRoutingSources, std::extent_v, streamRoutingDestinations, std::extent_v); + auto* techniqueState = context.GetZoneAssetDumperState(); for (const auto* technique : techset.techniques) { @@ -158,7 +184,7 @@ namespace { const auto commonTechnique = ConvertToCommonTechnique(*technique); - techset::DumpCommonTechnique(context, commonTechnique); + techset::DumpCommonTechnique(routingInfos, context, commonTechnique); } } } diff --git a/src/ObjWriting/Techset/CommonTechniqueDumper.cpp b/src/ObjWriting/Techset/CommonTechniqueDumper.cpp index 9e497da5..a76358a1 100644 --- a/src/ObjWriting/Techset/CommonTechniqueDumper.cpp +++ b/src/ObjWriting/Techset/CommonTechniqueDumper.cpp @@ -21,8 +21,9 @@ namespace class TechniqueFileWriter : public AbstractTextDumper { public: - explicit TechniqueFileWriter(std::ostream& stream) - : AbstractTextDumper(stream) + TechniqueFileWriter(const CommonStreamRoutingInfos& routingInfos, std::ostream& stream) + : AbstractTextDumper(stream), + m_routing_infos(routingInfos) { } @@ -66,9 +67,9 @@ namespace #endif DumpStateMap(); - DumpShader(pass, pass.m_vertex_shader, TechniqueShaderType::VERTEX_SHADER); - DumpShader(pass, pass.m_pixel_shader, TechniqueShaderType::PIXEL_SHADER); - // DumpVertexDecl(pass); + DumpShader(pass.m_vertex_shader, TechniqueShaderType::VERTEX_SHADER, pass.m_dx_version); + DumpShader(pass.m_pixel_shader, TechniqueShaderType::PIXEL_SHADER, pass.m_dx_version); + DumpVertexDecl(pass.m_vertex_declaration); DecIndent(); m_stream << "}\n"; @@ -82,7 +83,7 @@ namespace m_stream << "stateMap \"passthrough\"; // TODO\n"; } - void DumpShader(const CommonPass& pass, const CommonTechniqueShader& shader, const TechniqueShaderType shaderType) const + void DumpShader(const CommonTechniqueShader& shader, const TechniqueShaderType shaderType, const DxVersion dxVersion) const { if (!shader.m_shader_bin) { @@ -93,7 +94,7 @@ namespace } unsigned versionMajor, versionMinor; - if (pass.m_dx_version == DxVersion::DX9) + if (dxVersion == DxVersion::DX9) { const auto shaderInfo = d3d9::ShaderAnalyser::GetShaderInfo(shader.m_shader_bin, shader.m_shader_bin_size); assert(shaderInfo); @@ -105,7 +106,7 @@ namespace } else { - assert(pass.m_dx_version == DxVersion::DX11); + assert(dxVersion == DxVersion::DX11); const auto shaderInfo = d3d11::ShaderAnalyser::GetShaderInfo(shader.m_shader_bin, shader.m_shader_bin_size); assert(shaderInfo); if (!shaderInfo) @@ -126,17 +127,34 @@ namespace Indent(); m_stream << "}\n"; } + + void DumpVertexDecl(const CommonVertexDeclaration& vertexDeclaration) const + { + if (vertexDeclaration.m_routing.empty()) + return; + + m_stream << "\n"; + + for (const auto& routing : vertexDeclaration.m_routing) + { + Indent(); + m_stream << std::format( + "vertex.{} = code.{};\n", m_routing_infos.GetDestinationName(routing.m_destination), m_routing_infos.GetSourceName(routing.m_source)); + } + } + + const CommonStreamRoutingInfos& m_routing_infos; }; } // namespace namespace techset { - void DumpCommonTechnique(const AssetDumpingContext& context, const CommonTechnique& technique) + void DumpCommonTechnique(const CommonStreamRoutingInfos& routingInfos, const AssetDumpingContext& context, const CommonTechnique& technique) { const auto techniqueFile = context.OpenAssetFile(GetFileNameForTechniqueName(technique.m_name)); if (techniqueFile) { - TechniqueFileWriter writer(*techniqueFile); + TechniqueFileWriter writer(routingInfos, *techniqueFile); writer.DumpTechnique(technique); } } diff --git a/src/ObjWriting/Techset/CommonTechniqueDumper.h b/src/ObjWriting/Techset/CommonTechniqueDumper.h index d541414a..3794d71d 100644 --- a/src/ObjWriting/Techset/CommonTechniqueDumper.h +++ b/src/ObjWriting/Techset/CommonTechniqueDumper.h @@ -5,5 +5,5 @@ namespace techset { - void DumpCommonTechnique(const AssetDumpingContext& context, const CommonTechnique& technique); + void DumpCommonTechnique(const CommonStreamRoutingInfos& routingInfos, const AssetDumpingContext& context, const CommonTechnique& technique); } // namespace techset From f1485fa23046ececc54139c2d93e9ef6b661ae95 Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Sat, 15 Nov 2025 19:21:43 +0000 Subject: [PATCH 4/5] chore: move ShaderDumpingZoneState to non-game specific code --- .../Game/T6/Techset/TechsetDumperT6.cpp | 48 +------------------ .../Techset/ShaderDumpingZoneState.cpp | 31 ++++++++++++ .../Techset/ShaderDumpingZoneState.h | 21 ++++++++ .../Techset/TechniqueDumpingZoneState.cpp | 2 +- 4 files changed, 55 insertions(+), 47 deletions(-) create mode 100644 src/ObjWriting/Techset/ShaderDumpingZoneState.cpp create mode 100644 src/ObjWriting/Techset/ShaderDumpingZoneState.h diff --git a/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp b/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp index e2191c59..e2c6604e 100644 --- a/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp +++ b/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp @@ -4,6 +4,7 @@ #include "Shader/ShaderCommon.h" #include "Techset/CommonTechniqueDumper.h" #include "Techset/CommonTechsetDumper.h" +#include "Techset/ShaderDumpingZoneState.h" #include "Techset/TechniqueDumpingZoneState.h" #include @@ -12,51 +13,6 @@ using namespace T6; namespace { - class ShaderZoneState final : public IZoneAssetDumperState - { - public: - bool ShouldDumpTechnique(const MaterialTechnique* technique) - { - const auto existingTechnique = m_dumped_techniques.find(technique); - if (existingTechnique == m_dumped_techniques.end()) - { - m_dumped_techniques.emplace(technique); - return true; - } - - return false; - } - - bool ShouldDumpPixelShader(const MaterialPixelShader* pixelShader) - { - const auto existingPixelShader = m_dumped_pixel_shaders.find(pixelShader); - if (existingPixelShader == m_dumped_pixel_shaders.end()) - { - m_dumped_pixel_shaders.emplace(pixelShader); - return true; - } - - return false; - } - - bool ShouldDumpVertexShader(const MaterialVertexShader* vertexShader) - { - const auto existingVertexShader = m_dumped_vertex_shaders.find(vertexShader); - if (existingVertexShader == m_dumped_vertex_shaders.end()) - { - m_dumped_vertex_shaders.emplace(vertexShader); - return true; - } - - return false; - } - - private: - std::unordered_set m_dumped_techniques; - std::unordered_set m_dumped_pixel_shaders; - std::unordered_set m_dumped_vertex_shaders; - }; - void DumpPixelShader(const AssetDumpingContext& context, const MaterialPixelShader& pixelShader) { const auto shaderFile = context.OpenAssetFile(shader::GetFileNameForPixelShaderAssetName(pixelShader.name)); @@ -79,7 +35,7 @@ namespace void DumpShaders(AssetDumpingContext& context, const MaterialTechniqueSet& techset) { - auto* shaderState = context.GetZoneAssetDumperState(); + auto* shaderState = context.GetZoneAssetDumperState(); for (const auto* technique : techset.techniques) { diff --git a/src/ObjWriting/Techset/ShaderDumpingZoneState.cpp b/src/ObjWriting/Techset/ShaderDumpingZoneState.cpp new file mode 100644 index 00000000..23e84712 --- /dev/null +++ b/src/ObjWriting/Techset/ShaderDumpingZoneState.cpp @@ -0,0 +1,31 @@ +#include "ShaderDumpingZoneState.h" + +namespace techset +{ + bool ShaderDumpingZoneState::ShouldDumpTechnique(const void* technique) + { + if (m_dumped_techniques.contains(technique)) + return false; + + m_dumped_techniques.emplace(technique); + return true; + } + + bool ShaderDumpingZoneState::ShouldDumpVertexShader(const void* vertexShader) + { + if (m_dumped_vertex_shaders.contains(vertexShader)) + return false; + + m_dumped_vertex_shaders.emplace(vertexShader); + return true; + } + + bool ShaderDumpingZoneState::ShouldDumpPixelShader(const void* pixelShader) + { + if (m_dumped_pixel_shaders.contains(pixelShader)) + return false; + + m_dumped_pixel_shaders.emplace(pixelShader); + return true; + } +} // namespace techset diff --git a/src/ObjWriting/Techset/ShaderDumpingZoneState.h b/src/ObjWriting/Techset/ShaderDumpingZoneState.h new file mode 100644 index 00000000..18182598 --- /dev/null +++ b/src/ObjWriting/Techset/ShaderDumpingZoneState.h @@ -0,0 +1,21 @@ +#pragma once + +#include "Dumping/IZoneAssetDumperState.h" + +#include + +namespace techset +{ + class ShaderDumpingZoneState final : public IZoneAssetDumperState + { + public: + bool ShouldDumpTechnique(const void* technique); + bool ShouldDumpVertexShader(const void* vertexShader); + bool ShouldDumpPixelShader(const void* pixelShader); + + private: + std::unordered_set m_dumped_techniques; + std::unordered_set m_dumped_vertex_shaders; + std::unordered_set m_dumped_pixel_shaders; + }; +} // namespace techset diff --git a/src/ObjWriting/Techset/TechniqueDumpingZoneState.cpp b/src/ObjWriting/Techset/TechniqueDumpingZoneState.cpp index 7ca2e43d..2469e41a 100644 --- a/src/ObjWriting/Techset/TechniqueDumpingZoneState.cpp +++ b/src/ObjWriting/Techset/TechniqueDumpingZoneState.cpp @@ -4,7 +4,7 @@ namespace techset { bool TechniqueDumpingZoneState::ShouldDumpTechnique(const void* technique) { - if (m_dumped_techniques.find(technique) != m_dumped_techniques.end()) + if (m_dumped_techniques.contains(technique)) return false; m_dumped_techniques.emplace(technique); From dadcdc84e0c6fc3a306d3480f831ade75c651eb2 Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Sun, 16 Nov 2025 00:12:52 +0000 Subject: [PATCH 5/5] feat: dump t6 shader args --- src/Common/Game/T6/T6_Assets.h | 66 +- .../Game/T6/Techset/TechsetConstantsT6.h | 1601 +++++++++++++++++ src/ObjCommon/Techset/CommonTechnique.cpp | 53 + src/ObjCommon/Techset/CommonTechnique.h | 101 +- .../Material/MaterialConstantZoneStateIW3.cpp | 7 +- .../Material/MaterialConstantZoneStateIW3.h | 2 +- .../Material/MaterialConstantZoneStateIW4.cpp | 7 +- .../Material/MaterialConstantZoneStateIW4.h | 2 +- .../Material/MaterialConstantZoneStateIW5.cpp | 7 +- .../Material/MaterialConstantZoneStateIW5.h | 2 +- .../Material/MaterialConstantZoneStateT5.cpp | 7 +- .../T5/Material/MaterialConstantZoneStateT5.h | 4 +- .../Material/MaterialConstantZoneStateT6.cpp | 7 +- .../T6/Material/MaterialConstantZoneStateT6.h | 2 +- .../Game/T6/Techset/TechsetDumperT6.cpp | 222 ++- .../Game/T6/Techset/TechsetDumperT6.h | 2 + .../AbstractMaterialConstantZoneState.cpp | 31 +- .../AbstractMaterialConstantZoneState.h | 8 +- .../Material/MaterialJsonDumper.cpp.template | 2 +- .../Techset/CommonTechniqueDumper.cpp | 272 ++- .../Techset/CommonTechniqueDumper.h | 7 +- 21 files changed, 2341 insertions(+), 71 deletions(-) diff --git a/src/Common/Game/T6/T6_Assets.h b/src/Common/Game/T6/T6_Assets.h index 366c93f7..6368cf98 100644 --- a/src/Common/Game/T6/T6_Assets.h +++ b/src/Common/Game/T6/T6_Assets.h @@ -5862,8 +5862,8 @@ namespace T6 struct { - char textureIndex; - char samplerIndex; + uint8_t textureIndex; + uint8_t samplerIndex; }; }; @@ -5948,7 +5948,6 @@ namespace T6 CONST_SRC_CODE_DEPTH_FROM_CLIP = 0x42, CONST_SRC_CODE_CODE_MESH_ARG_0 = 0x43, CONST_SRC_CODE_CODE_MESH_ARG_1 = 0x44, - CONST_SRC_CODE_CODE_MESH_ARG_LAST = 0x44, CONST_SRC_CODE_GRID_LIGHTING_COORDS_AND_VIS = 0x45, CONST_SRC_CODE_GRID_LIGHTING_SH_0 = 0x46, CONST_SRC_CODE_GRID_LIGHTING_SH_1 = 0x47, @@ -6133,6 +6132,67 @@ namespace T6 CONST_SRC_NONE, }; + enum MaterialTextureSource + { + TEXTURE_SRC_CODE_BLACK = 0x0, + TEXTURE_SRC_CODE_WHITE = 0x1, + TEXTURE_SRC_CODE_IDENTITY_NORMAL_MAP = 0x2, + TEXTURE_SRC_CODE_MODEL_LIGHTING = 0x3, + TEXTURE_SRC_CODE_LIGHTMAP_PRIMARY = 0x4, + TEXTURE_SRC_CODE_LIGHTMAP_SECONDARY = 0x5, + TEXTURE_SRC_CODE_SHADOWMAP_SUN = 0x6, + TEXTURE_SRC_CODE_SHADOWMAP_SPOT = 0x7, + TEXTURE_SRC_CODE_FEEDBACK = 0x8, + TEXTURE_SRC_CODE_RESOLVED_POST_SUN = 0x9, + TEXTURE_SRC_CODE_RESOLVED_SCENE = 0xA, + TEXTURE_SRC_CODE_POST_EFFECT_SRC = 0xB, + TEXTURE_SRC_CODE_POST_EFFECT_GODRAYS = 0xC, + TEXTURE_SRC_CODE_POST_EFFECT_0 = 0xD, + TEXTURE_SRC_CODE_POST_EFFECT_1 = 0xE, + TEXTURE_SRC_CODE_LIGHT_ATTENUATION = 0xF, + TEXTURE_SRC_CODE_DLIGHT_ATTENUATION = 0x10, + TEXTURE_SRC_CODE_OUTDOOR = 0x11, + TEXTURE_SRC_CODE_FLOATZ = 0x12, + TEXTURE_SRC_CODE_PROCESSED_FLOATZ = 0x13, + TEXTURE_SRC_CODE_RAW_FLOATZ = 0x14, + TEXTURE_SRC_CODE_STENCIL = 0x15, + TEXTURE_SRC_CODE_CINEMATIC_Y = 0x16, + TEXTURE_SRC_CODE_CINEMATIC_CR = 0x17, + TEXTURE_SRC_CODE_CINEMATIC_CB = 0x18, + TEXTURE_SRC_CODE_CINEMATIC_A = 0x19, + TEXTURE_SRC_CODE_REFLECTION_PROBE = 0x1A, + TEXTURE_SRC_CODE_FEATHER_FLOAT_Z = 0x1B, + TEXTURE_SRC_CODE_TEXTURE_0 = 0x1C, + TEXTURE_SRC_CODE_TEXTURE_1 = 0x1D, + TEXTURE_SRC_CODE_TEXTURE_2 = 0x1E, + TEXTURE_SRC_CODE_TEXTURE_3 = 0x1F, + TEXTURE_SRC_CODE_IMPACT_MASK_DEPRECATED = 0x20, + TEXTURE_SRC_CODE_UI3D = 0x21, + TEXTURE_SRC_CODE_MISSILE_CAM = 0x22, + TEXTURE_SRC_CODE_MISSILE_CAM_0 = 0x23, + TEXTURE_SRC_CODE_MISSILE_CAM_1 = 0x24, + TEXTURE_SRC_CODE_MISSILE_CAM_2 = 0x25, + TEXTURE_SRC_CODE_MISSILE_CAM_3 = 0x26, + TEXTURE_SRC_CODE_COMPOSITE_RESULT = 0x27, + TEXTURE_SRC_CODE_HEATMAP = 0x28, + TEXTURE_SRC_CODE_SONAR_COLOR = 0x29, + TEXTURE_SRC_CODE_SONAR_DEPTH = 0x2A, + TEXTURE_SRC_CODE_QRCODE_0 = 0x2B, + TEXTURE_SRC_CODE_QRCODE_1 = 0x2C, + TEXTURE_SRC_CODE_QRCODE_2 = 0x2D, + TEXTURE_SRC_CODE_QRCODE_3 = 0x2E, + TEXTURE_SRC_CODE_QRCODE_4 = 0x2F, + TEXTURE_SRC_CODE_QRCODE_5 = 0x30, + TEXTURE_SRC_CODE_QRCODE_6 = 0x31, + TEXTURE_SRC_CODE_QRCODE_7 = 0x32, + TEXTURE_SRC_CODE_QRCODE_8 = 0x33, + TEXTURE_SRC_CODE_QRCODE_9 = 0x34, + TEXTURE_SRC_CODE_QRCODE_10 = 0x35, + TEXTURE_SRC_CODE_QRCODE_11 = 0x36, + + TEXTURE_SRC_CODE_COUNT + }; + struct CodeConstantSource { const char* name; diff --git a/src/ObjCommon/Game/T6/Techset/TechsetConstantsT6.h b/src/ObjCommon/Game/T6/Techset/TechsetConstantsT6.h index 72237e82..4e773c3e 100644 --- a/src/ObjCommon/Game/T6/Techset/TechsetConstantsT6.h +++ b/src/ObjCommon/Game/T6/Techset/TechsetConstantsT6.h @@ -188,6 +188,1607 @@ namespace T6 }; static_assert(std::extent_v == STREAM_DST_COUNT); + static techset::CommonCodeConstSourceInfo commonCodeConstSources[]{ + { + .value = CONST_SRC_CODE_LIGHT_POSITION, + .accessor = "lightPosition", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_LIGHT_DIFFUSE, + .accessor = "lightDiffuse", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_LIGHT_SPOTDIR, + .accessor = "lightSpotDir", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_LIGHT_SPOTFACTORS, + .accessor = "lightSpotFactors", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_LIGHT_ATTENUATION, + .accessor = "lightAttenuation", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_LIGHT_FALLOFF_A, + .accessor = "lightFallOffA", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_LIGHT_FALLOFF_B, + .accessor = "lightFallOffB", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_LIGHT_SPOT_MATRIX0, + .accessor = "lightSpotMatrix0", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_LIGHT_SPOT_MATRIX1, + .accessor = "lightSpotMatrix1", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_LIGHT_SPOT_MATRIX2, + .accessor = "lightSpotMatrix2", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_LIGHT_SPOT_MATRIX3, + .accessor = "lightSpotMatrix3", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_LIGHT_SPOT_AABB, + .accessor = "lightSpotAABB", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_LIGHT_CONE_CONTROL1, + .accessor = "lightConeControl1", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_LIGHT_CONE_CONTROL2, + .accessor = "lightConeControl2", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_LIGHT_SPOT_COOKIE_SLIDE_CONTROL, + .accessor = "lightSpotCookieSlideControl", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_SHADOW_PARMS, + .accessor = "shadowParms", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_SHADOWMAP_POLYGON_OFFSET, + .accessor = "shadowmapPolygonOffset", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_RENDER_TARGET_SIZE, + .accessor = "renderTargetSize", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_UPSCALED_TARGET_SIZE, + .accessor = "upscaledTargetSize", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_DOF_EQUATION_VIEWMODEL_AND_FAR_BLUR, + .accessor = "dofEquationViewModelAndFarBlur", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_DOF_EQUATION_SCENE, + .accessor = "dofEquationScene", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_DOF_LERP_SCALE, + .accessor = "dofLerpScale", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_DOF_LERP_BIAS, + .accessor = "dofLerpBias", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_DOF_ROW_DELTA, + .accessor = "dofRowDelta", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_PARTICLE_CLOUD_COLOR, + .accessor = "particleCloudColor", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_GAMETIME, + .accessor = "gameTime", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_FILTER_TAP_0, + .accessor = "filterTap", + .arrayCount = 8, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_COLOR_MATRIX_R, + .accessor = "colorMatrixR", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_COLOR_MATRIX_G, + .accessor = "colorMatrixG", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_COLOR_MATRIX_B, + .accessor = "colorMatrixB", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_SHADOWMAP_SWITCH_PARTITION, + .accessor = "shadowmapSwitchPartition", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_SUNSHADOWMAP_PIXEL_SIZE, + .accessor = "sunShadowmapPixelSize", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_SHADOWMAP_SCALE, + .accessor = "shadowmapScale", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_ZNEAR, + .accessor = "zNear", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_SUN_POSITION, + .accessor = "sunPosition", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_SUN_DIFFUSE, + .accessor = "sunDiffuse", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_LIGHTING_LOOKUP_SCALE, + .accessor = "lightingLookupScale", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_DEBUG_BUMPMAP, + .accessor = "debugBumpmap", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_DEBUG_PERFORMANCE, + .accessor = "debugPerformance", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_MATERIAL_COLOR, + .accessor = "materialColor", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_FOG, + .accessor = "fogConsts", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_FOG2, + .accessor = "fogConsts2", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_FOG_COLOR, + .accessor = "fogColor", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_SUN_FOG, + .accessor = "sunFog", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_SUN_FOG_DIR, + .accessor = "sunFogDir", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_SUN_FOG_COLOR, + .accessor = "sunFogColor", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_GLOW_SETUP, + .accessor = "glowSetup", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_GLOW_APPLY, + .accessor = "glowApply", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_COLOR_BIAS, + .accessor = "colorBias", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_COLOR_TINT_BASE, + .accessor = "colorTintBase", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_COLOR_TINT_DELTA, + .accessor = "colorTintDelta", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_OUTDOOR_FEATHER_PARMS, + .accessor = "outdoorFeatherParms", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_SKY_TRANSITION, + .accessor = "skyTransition", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_SPOT_SHADOWMAP_PIXEL_ADJUST, + .accessor = "spotShadowmapPixelAdjust", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_DLIGHT_SPOT_SHADOWMAP_PIXEL_ADJUST, + .accessor = "dlightSpotShadowmapPixelAdjust", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_CLIP_SPACE_LOOKUP_SCALE, + .accessor = "clipSpaceLookupScale", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = CONST_SRC_CODE_CLIP_SPACE_LOOKUP_OFFSET, + .accessor = "clipSpaceLookupOffset", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = CONST_SRC_CODE_PARTICLE_CLOUD_MATRIX, + .accessor = "particleCloudMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = CONST_SRC_CODE_PARTICLE_CLOUD_VEL_WORLD, + .accessor = "particleCloudVelWorld", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = CONST_SRC_CODE_DEPTH_FROM_CLIP, + .accessor = "depthFromClip", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = CONST_SRC_CODE_CODE_MESH_ARG_0, + .accessor = "codeMeshArg", + .arrayCount = 2, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = CONST_SRC_CODE_GRID_LIGHTING_COORDS_AND_VIS, + .accessor = "gridLightingCoordsAndVis", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + { + .value = CONST_SRC_CODE_GRID_LIGHTING_SH_0, + .accessor = "gridLightingSH0", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + { + .value = CONST_SRC_CODE_GRID_LIGHTING_SH_1, + .accessor = "gridLightingSH1", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + { + .value = CONST_SRC_CODE_GRID_LIGHTING_SH_2, + .accessor = "gridLightingSH2", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + { + .value = CONST_SRC_CODE_REFLECTION_LIGHTING_SH_0, + .accessor = "reflectionLightingSH0", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_REFLECTION_LIGHTING_SH_1, + .accessor = "reflectionLightingSH1", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_REFLECTION_LIGHTING_SH_2, + .accessor = "reflectionLightingSH2", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_WIND_DIRECTION, + .accessor = "windDirection", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_MOTIONBLUR_DIRECTION_AND_MAGNITUDE, + .accessor = "motionblurDirectionAndMagnitude", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_COMPOSITE_FX_DISTORTION, + .accessor = "flameDistortion", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_GLOW_BLOOM_SCALE, + .accessor = "bloomScale", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_COMPOSITE_FX_OVERLAY_TEXCOORD, + .accessor = "overlayTexCoord", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_COLOR_BIAS1, + .accessor = "colorBias1", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_COLOR_TINT_BASE1, + .accessor = "colorTintBase1", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_COLOR_TINT_DELTA1, + .accessor = "colorTintDelta1", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_POSTFX_FADE_EFFECT, + .accessor = "fadeEffect", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_VIEWPORT_DIMENSIONS, + .accessor = "viewportDimensions", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_FRAMEBUFFER_READ, + .accessor = "framebufferRead", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_RESIZE_PARAMS1, + .accessor = "resizeParams1", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_RESIZE_PARAMS2, + .accessor = "resizeParams2", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_RESIZE_PARAMS3, + .accessor = "resizeParams3", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_VARIANT_WIND_SPRING_0, + .accessor = "variantWindSpring", + .arrayCount = 16, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_CHARACTER_CHARRED_AMOUNT, + .accessor = "_characterCharredAmount", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_POSTFX_CONTROL0, + .accessor = "postFxControl0", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_POSTFX_CONTROL1, + .accessor = "postFxControl1", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_POSTFX_CONTROL2, + .accessor = "postFxControl2", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_POSTFX_CONTROL3, + .accessor = "postFxControl3", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_POSTFX_CONTROL4, + .accessor = "postFxControl4", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_POSTFX_CONTROL5, + .accessor = "postFxControl5", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_POSTFX_CONTROL6, + .accessor = "postFxControl6", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_POSTFX_CONTROL7, + .accessor = "postFxControl7", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_POSTFX_CONTROL8, + .accessor = "postFxControl8", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_POSTFX_CONTROL9, + .accessor = "postFxControl9", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_POSTFX_CONTROLA, + .accessor = "postFxControlA", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_POSTFX_CONTROLB, + .accessor = "postFxControlB", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_POSTFX_CONTROLC, + .accessor = "postFxControlC", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_POSTFX_CONTROLD, + .accessor = "postFxControlD", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_POSTFX_CONTROLE, + .accessor = "postFxControlE", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_POSTFX_CONTROLF, + .accessor = "postFxControlF", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_HDRCONTROL_0, + .accessor = "hdrControl0", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_HDRCONTROL_1, + .accessor = "hdrControl1", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_GLIGHT_POSXS, + .accessor = "glightPosXs", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_GLIGHT_POSYS, + .accessor = "glightPosYs", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_GLIGHT_POSZS, + .accessor = "glightPosZs", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_GLIGHT_FALLOFFS, + .accessor = "glightFallOffs", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_GLIGHT_REDS, + .accessor = "glightReds", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_GLIGHT_GREENS, + .accessor = "glightGreens", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_GLIGHT_BLUES, + .accessor = "glightBlues", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_DLIGHT_POSITION, + .accessor = "dlightPosition", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_DLIGHT_DIFFUSE, + .accessor = "dlightDiffuse", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_DLIGHT_ATTENUATION, + .accessor = "dlightAttenuation", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_DLIGHT_FALLOFF, + .accessor = "dlightFallOff", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_DLIGHT_SPOT_MATRIX_0, + .accessor = "dlightSpotMatrix0", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_DLIGHT_SPOT_MATRIX_1, + .accessor = "dlightSpotMatrix1", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_DLIGHT_SPOT_MATRIX_2, + .accessor = "dlightSpotMatrix2", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_DLIGHT_SPOT_MATRIX_3, + .accessor = "dlightSpotMatrix3", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_DLIGHT_SPOT_DIR, + .accessor = "dlightSpotDir", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_DLIGHT_SPOT_FACTORS, + .accessor = "dlightSpotFactors", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_DLIGHT_SHADOW_LOOKUP_MATRIX_0, + .accessor = "dlightShadowLookupMatrix0", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_DLIGHT_SHADOW_LOOKUP_MATRIX_1, + .accessor = "dlightShadowLookupMatrix1", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_DLIGHT_SHADOW_LOOKUP_MATRIX_2, + .accessor = "dlightShadowLookupMatrix2", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_DLIGHT_SHADOW_LOOKUP_MATRIX_3, + .accessor = "dlightShadowLookupMatrix3", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_CLOUD_LAYER_CONTROL0, + .accessor = "cloudLayerControl0", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_CLOUD_LAYER_CONTROL1, + .accessor = "cloudLayerControl1", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_CLOUD_LAYER_CONTROL2, + .accessor = "cloudLayerControl2", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_CLOUD_LAYER_CONTROL3, + .accessor = "cloudLayerControl3", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_CLOUD_LAYER_CONTROL4, + .accessor = "cloudLayerControl4", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_HERO_LIGHTING_R, + .accessor = "heroLightingR", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_HERO_LIGHTING_G, + .accessor = "heroLightingG", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_HERO_LIGHTING_B, + .accessor = "heroLightingB", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_LIGHT_HERO_SCALE, + .accessor = "lightHeroScale", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_CINEMATIC_BLUR_BOX, + .accessor = "cinematicBlurBox", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_CINEMATIC_BLUR_BOX2, + .accessor = "cinematicBlurBox2", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_ADSZSCALE, + .accessor = "adsZScale", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_UI3D_UV_SETUP_0, + .accessor = "ui3dUVSetup0", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_UI3D_UV_SETUP_1, + .accessor = "ui3dUVSetup1", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_UI3D_UV_SETUP_2, + .accessor = "ui3dUVSetup2", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_UI3D_UV_SETUP_3, + .accessor = "ui3dUVSetup3", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_UI3D_UV_SETUP_4, + .accessor = "ui3dUVSetup4", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_UI3D_UV_SETUP_5, + .accessor = "ui3dUVSetup5", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_CHARACTER_DISSOLVE_COLOR, + .accessor = "_characterDissolveColor", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_CAMERA_LOOK, + .accessor = "cameraLook", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_CAMERA_UP, + .accessor = "cameraUp", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_CAMERA_SIDE, + .accessor = "cameraSide", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_RIMINTENSITY, + .accessor = "rimIntensity", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_GENERIC_PARAM0, + .accessor = "scriptVector0", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_GENERIC_PARAM1, + .accessor = "scriptVector1", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_GENERIC_PARAM2, + .accessor = "scriptVector2", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_GENERIC_PARAM3, + .accessor = "scriptVector3", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_GENERIC_PARAM4, + .accessor = "scriptVector4", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_GENERIC_PARAM5, + .accessor = "scriptVector5", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_GENERIC_PARAM6, + .accessor = "scriptVector6", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_GENERIC_PARAM7, + .accessor = "scriptVector7", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_GENERIC_EYEOFFSET, + .accessor = "genericEyeOffset", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_GENERIC_QUADINTENSITY, + .accessor = "genericQuadIntensity", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_WEAPON_PARAM0, + .accessor = "weaponParam0", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_WEAPON_PARAM1, + .accessor = "weaponParam1", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_WEAPON_PARAM2, + .accessor = "weaponParam2", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_WEAPON_PARAM3, + .accessor = "weaponParam3", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_WEAPON_PARAM4, + .accessor = "weaponParam4", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_WEAPON_PARAM5, + .accessor = "weaponParam5", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_WEAPON_PARAM6, + .accessor = "weaponParam6", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_WEAPON_PARAM7, + .accessor = "weaponParam7", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_WEAPON_PARAM8, + .accessor = "weaponParam8", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_WEAPON_PARAM9, + .accessor = "weaponParam9", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_QRCODE_0, + .accessor = "qrcode0", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_QRCODE_1, + .accessor = "qrcode1", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_QRCODE_2, + .accessor = "qrcode2", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_QRCODE_3, + .accessor = "qrcode3", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_QRCODE_4, + .accessor = "qrcode4", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_QRCODE_5, + .accessor = "qrcode5", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_QRCODE_6, + .accessor = "qrcode6", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_QRCODE_7, + .accessor = "qrcode7", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_QRCODE_8, + .accessor = "qrcode8", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_QRCODE_9, + .accessor = "qrcode9", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_QRCODE_10, + .accessor = "qrcode10", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_QRCODE_11, + .accessor = "qrcode11", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_EYEOFFSET, + .accessor = "eyeOffset", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = CONST_SRC_CODE_SKY_COLOR_MULTIPLIER, + .accessor = "skyColorMultiplier", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_EXTRA_CAM_PARAM, + .accessor = "extraCamParam", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_EMBLEM_LUT_SELECTOR, + .accessor = "emblemLUTSelector", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_DEBUG_COLOR_OVERRIDE, + .accessor = "debugColorOverride", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_DEBUG_ALPHA_OVERRIDE, + .accessor = "debugAlphaOverride", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_DEBUG_NORMAL_OVERRIDE, + .accessor = "debugNormalOverride", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_DEBUG_SPECULAR_OVERRIDE, + .accessor = "debugSpecularOverride", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_DEBUG_GLOSS_OVERRIDE, + .accessor = "debugGlossOverride", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_DEBUG_OCCLUSION_OVERRIDE, + .accessor = "debugOcclusionOverride", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_WORLD_MATRIX, + .accessor = "worldMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + { + .value = CONST_SRC_CODE_INVERSE_WORLD_MATRIX, + .accessor = "inverseWorldMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + { + .value = CONST_SRC_CODE_TRANSPOSE_WORLD_MATRIX, + .accessor = "transposeWorldMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + { + .value = CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_MATRIX, + .accessor = "inverseTransposeWorldMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + { + .value = CONST_SRC_CODE_VIEW_MATRIX, + .accessor = "viewMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_INVERSE_VIEW_MATRIX, + .accessor = "inverseViewMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_TRANSPOSE_VIEW_MATRIX, + .accessor = "transposeViewMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_INVERSE_TRANSPOSE_VIEW_MATRIX, + .accessor = "inverseTransposeViewMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_PROJECTION_MATRIX, + .accessor = "projectionMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = CONST_SRC_CODE_INVERSE_PROJECTION_MATRIX, + .accessor = "inverseProjectionMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = CONST_SRC_CODE_TRANSPOSE_PROJECTION_MATRIX, + .accessor = "transposeProjectionMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = CONST_SRC_CODE_INVERSE_TRANSPOSE_PROJECTION_MATRIX, + .accessor = "inverseTransposeProjectionMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = CONST_SRC_CODE_WORLD_VIEW_MATRIX, + .accessor = "worldViewMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + { + .value = CONST_SRC_CODE_INVERSE_WORLD_VIEW_MATRIX, + .accessor = "inverseWorldViewMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + { + .value = CONST_SRC_CODE_TRANSPOSE_WORLD_VIEW_MATRIX, + .accessor = "transposeWorldViewMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + { + .value = CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_VIEW_MATRIX, + .accessor = "inverseTransposeWorldViewMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + { + .value = CONST_SRC_CODE_VIEW_PROJECTION_MATRIX, + .accessor = "viewProjectionMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = CONST_SRC_CODE_INVERSE_VIEW_PROJECTION_MATRIX, + .accessor = "inverseViewProjectionMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = CONST_SRC_CODE_TRANSPOSE_VIEW_PROJECTION_MATRIX, + .accessor = "transposeViewProjectionMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = CONST_SRC_CODE_INVERSE_TRANSPOSE_VIEW_PROJECTION_MATRIX, + .accessor = "inverseTransposeViewProjectionMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = CONST_SRC_CODE_WORLD_VIEW_PROJECTION_MATRIX, + .accessor = "worldViewProjectionMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + { + .value = CONST_SRC_CODE_INVERSE_WORLD_VIEW_PROJECTION_MATRIX, + .accessor = "inverseWorldViewProjectionMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + { + .value = CONST_SRC_CODE_TRANSPOSE_WORLD_VIEW_PROJECTION_MATRIX, + .accessor = "transposeWorldViewProjectionMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + { + .value = CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_VIEW_PROJECTION_MATRIX, + .accessor = "inverseTransposeWorldViewProjectionMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + { + .value = CONST_SRC_CODE_SHADOW_LOOKUP_MATRIX, + .accessor = "shadowLookupMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_INVERSE_SHADOW_LOOKUP_MATRIX, + .accessor = "inverseShadowLookupMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_TRANSPOSE_SHADOW_LOOKUP_MATRIX, + .accessor = "transposeShadowLookupMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_INVERSE_TRANSPOSE_SHADOW_LOOKUP_MATRIX, + .accessor = "inverseTransposeShadowLookupMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = CONST_SRC_CODE_WORLD_OUTDOOR_LOOKUP_MATRIX, + .accessor = "worldOutdoorLookupMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + { + .value = CONST_SRC_CODE_INVERSE_WORLD_OUTDOOR_LOOKUP_MATRIX, + .accessor = "inverseWorldOutdoorLookupMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + { + .value = CONST_SRC_CODE_TRANSPOSE_WORLD_OUTDOOR_LOOKUP_MATRIX, + .accessor = "transposeWorldOutdoorLookupMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + { + .value = CONST_SRC_CODE_INVERSE_TRANSPOSE_WORLD_OUTDOOR_LOOKUP_MATRIX, + .accessor = "inverseTransposeWorldOutdoorLookupMatrix", + .arrayCount = 0, + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + }, + }; + + static techset::CommonCodeSamplerSourceInfo commonCodeSamplerSources[]{ + { + .value = TEXTURE_SRC_CODE_BLACK, + .accessor = "black", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_WHITE, + .accessor = "white", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_IDENTITY_NORMAL_MAP, + .accessor = "identityNormalMap", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_MODEL_LIGHTING, + .accessor = "modelLightingSampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_LIGHTMAP_PRIMARY, + .accessor = "lightmapSamplerPrimary", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = TEXTURE_SRC_CODE_LIGHTMAP_SECONDARY, + .accessor = "lightmapSamplerSecondary", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = TEXTURE_SRC_CODE_SHADOWMAP_SUN, + .accessor = "shadowmapSamplerSun", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_SHADOWMAP_SPOT, + .accessor = "shadowmapSamplerSpot", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_FEEDBACK, + .accessor = "feedbackSampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = TEXTURE_SRC_CODE_RESOLVED_POST_SUN, + .accessor = "resolvedPostSun", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_RESOLVED_SCENE, + .accessor = "resolvedScene", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_POST_EFFECT_SRC, + .accessor = "postEffectSrc", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_POST_EFFECT_GODRAYS, + .accessor = "postEffectGodRays", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_POST_EFFECT_0, + .accessor = "postEffect0", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_POST_EFFECT_1, + .accessor = "postEffect1", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_LIGHT_ATTENUATION, + .accessor = "attenuationSampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_DLIGHT_ATTENUATION, + .accessor = "dlightAttenuationSampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_OUTDOOR, + .accessor = "outdoor", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_FLOATZ, + .accessor = "floatZSampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_PROCESSED_FLOATZ, + .accessor = "processedFloatZSampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_RAW_FLOATZ, + .accessor = "rawFloatZSampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_STENCIL, + .accessor = "stencilSampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_CINEMATIC_Y, + .accessor = "cinematicYSampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = TEXTURE_SRC_CODE_CINEMATIC_CR, + .accessor = "cinematicCrSampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = TEXTURE_SRC_CODE_CINEMATIC_CB, + .accessor = "cinematicCbSampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = TEXTURE_SRC_CODE_CINEMATIC_A, + .accessor = "cinematicASampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = TEXTURE_SRC_CODE_REFLECTION_PROBE, + .accessor = "reflectionProbeSampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + }, + { + .value = TEXTURE_SRC_CODE_FEATHER_FLOAT_Z, + .accessor = "featherFloatZSampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_TEXTURE_0, + .accessor = "codeTexture0", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_TEXTURE_1, + .accessor = "codeTexture1", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_TEXTURE_2, + .accessor = "codeTexture2", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_TEXTURE_3, + .accessor = "codeTexture3", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_IMPACT_MASK_DEPRECATED, + .accessor = "impactMaskSampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_UI3D, + .accessor = "ui3dSampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_MISSILE_CAM, + .accessor = "missileCamSampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_MISSILE_CAM_0, + .accessor = "missileCam0Sampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_MISSILE_CAM_1, + .accessor = "missileCam1Sampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_MISSILE_CAM_2, + .accessor = "missileCam2Sampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_MISSILE_CAM_3, + .accessor = "missileCam3Sampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_COMPOSITE_RESULT, + .accessor = "compositeResult", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + }, + { + .value = TEXTURE_SRC_CODE_HEATMAP, + .accessor = "heatmapSampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_SONAR_COLOR, + .accessor = "sonarColorSampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_SONAR_DEPTH, + .accessor = "sonarDepthSampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_QRCODE_0, + .accessor = "qrcode0Sampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_QRCODE_1, + .accessor = "qrcode1Sampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_QRCODE_2, + .accessor = "qrcode2Sampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_QRCODE_3, + .accessor = "qrcode3Sampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_QRCODE_4, + .accessor = "qrcode4Sampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_QRCODE_5, + .accessor = "qrcode5Sampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_QRCODE_6, + .accessor = "qrcode6Sampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_QRCODE_7, + .accessor = "qrcode7Sampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_QRCODE_8, + .accessor = "qrcode8Sampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_QRCODE_9, + .accessor = "qrcode9Sampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_QRCODE_10, + .accessor = "qrcode10Sampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + { + .value = TEXTURE_SRC_CODE_QRCODE_11, + .accessor = "qrcode11Sampler", + .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + }, + }; + inline MaterialTypeInfo g_materialTypeInfo[]{ {"", "" }, {"m/", "m_" }, diff --git a/src/ObjCommon/Techset/CommonTechnique.cpp b/src/ObjCommon/Techset/CommonTechnique.cpp index 135e7a35..a28b2a9c 100644 --- a/src/ObjCommon/Techset/CommonTechnique.cpp +++ b/src/ObjCommon/Techset/CommonTechnique.cpp @@ -1,7 +1,60 @@ #include "CommonTechnique.h" +#include + namespace techset { + CommonCodeSourceInfos::CommonCodeSourceInfos(const CommonCodeConstSourceInfo* codeConstSourceInfos, + const size_t codeConstCount, + const CommonCodeSamplerSourceInfo* codeSamplerSourceInfos, + const size_t codeSamplerCount) + : m_code_const_source_infos(codeConstCount), + m_code_sampler_source_infos(codeSamplerCount) + { + std::copy(codeConstSourceInfos, &codeConstSourceInfos[codeConstCount], m_code_const_source_infos.data()); + std::ranges::sort(m_code_const_source_infos, + [](const CommonCodeConstSourceInfo& a, const CommonCodeConstSourceInfo& b) -> bool + { + return a.value < b.value; + }); + + std::copy(codeSamplerSourceInfos, &codeSamplerSourceInfos[codeSamplerCount], m_code_sampler_source_infos.data()); + std::ranges::sort(m_code_sampler_source_infos, + [](const CommonCodeSamplerSourceInfo& a, const CommonCodeSamplerSourceInfo& b) -> bool + { + return a.value < b.value; + }); + } + + std::optional CommonCodeSourceInfos::GetInfoForCodeConstSource(const CommonCodeConstSource codeConstSource) const + { + for (const auto& codeConstSourceInfo : m_code_const_source_infos) + { + const auto codeConstSourceInfoEnd = static_cast(codeConstSourceInfo.value) + codeConstSourceInfo.arrayCount; + if (codeConstSourceInfo.value <= codeConstSource && codeConstSourceInfoEnd >= codeConstSource) + return codeConstSourceInfo; + + if (codeConstSourceInfoEnd > codeConstSource) + return std::nullopt; + } + + return std::nullopt; + } + + std::optional CommonCodeSourceInfos::GetInfoForCodeSamplerSource(const CommonCodeSamplerSource codeSamplerSource) const + { + for (const auto& codeSamplerSourceInfo : m_code_sampler_source_infos) + { + if (codeSamplerSourceInfo.value == codeSamplerSource) + return codeSamplerSourceInfo; + + if (codeSamplerSourceInfo.value > codeSamplerSource) + return std::nullopt; + } + + return std::nullopt; + } + CommonStreamRoutingInfos::CommonStreamRoutingInfos(const CommonStreamRoutingSourceInfo* sourceInfos, const size_t sourceCount, const CommonStreamRoutingDestinationInfo* destinationNames, diff --git a/src/ObjCommon/Techset/CommonTechnique.h b/src/ObjCommon/Techset/CommonTechnique.h index 928f1e24..37dcfe3f 100644 --- a/src/ObjCommon/Techset/CommonTechnique.h +++ b/src/ObjCommon/Techset/CommonTechnique.h @@ -1,11 +1,19 @@ #pragma once +#include #include +#include #include #include namespace techset { + typedef std::uint8_t CommonStreamSource; + typedef std::uint8_t CommonStreamDestination; + + typedef std::uint8_t CommonCodeConstSource; + typedef std::uint8_t CommonCodeSamplerSource; + struct CommonStreamRoutingSourceInfo { const char* name; @@ -19,8 +27,44 @@ namespace techset const char* abbreviation; }; - typedef std::uint8_t CommonStreamSource; - typedef std::uint8_t CommonStreamDestination; + enum class CommonCodeSourceUpdateFrequency : std::uint8_t + { + PER_PRIM, + PER_OBJECT, + RARELY, + CUSTOM, + }; + + struct CommonCodeConstSourceInfo + { + CommonCodeConstSource value; + const char* accessor; + std::uint8_t arrayCount; + CommonCodeSourceUpdateFrequency updateFrequency; + }; + + struct CommonCodeSamplerSourceInfo + { + CommonCodeSamplerSource value; + const char* accessor; + CommonCodeSourceUpdateFrequency updateFrequency; + }; + + class CommonCodeSourceInfos + { + public: + CommonCodeSourceInfos(const CommonCodeConstSourceInfo* codeConstSourceInfos, + size_t codeConstCount, + const CommonCodeSamplerSourceInfo* codeSamplerSourceInfos, + size_t codeSamplerCount); + + [[nodiscard]] std::optional GetInfoForCodeConstSource(CommonCodeConstSource codeConstSource) const; + [[nodiscard]] std::optional GetInfoForCodeSamplerSource(CommonCodeSamplerSource codeSamplerSource) const; + + private: + std::vector m_code_const_source_infos; + std::vector m_code_sampler_source_infos; + }; class CommonStreamRoutingInfos { @@ -41,6 +85,58 @@ namespace techset std::vector m_destinations; }; + union CommonShaderArgValue + { + std::array literal_value; + CommonCodeConstSource code_const_source; + CommonCodeSamplerSource code_sampler_source; + unsigned name_hash; + }; + + class CommonShaderArgDestinationDx9 + { + public: + unsigned m_destination_register; + }; + + class CommonShaderArgDestinationDx11 + { + public: + // In case of a constant: Offset in constant buffer + // In case of a sampler: Index of sampler + unsigned m_location; + unsigned m_size; + unsigned m_buffer; + }; + + union CommonShaderArgDestination + { + CommonShaderArgDestinationDx9 dx9; + 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; + CommonShaderArgDestination m_destination; + CommonShaderArgValue m_value; + }; + class CommonStreamRouting { public: @@ -60,6 +156,7 @@ namespace techset std::string m_name; const void* m_shader_bin; size_t m_shader_bin_size; + std::vector m_args; }; enum class DxVersion : std::uint8_t diff --git a/src/ObjWriting/Game/IW3/Material/MaterialConstantZoneStateIW3.cpp b/src/ObjWriting/Game/IW3/Material/MaterialConstantZoneStateIW3.cpp index ab66127c..662b0604 100644 --- a/src/ObjWriting/Game/IW3/Material/MaterialConstantZoneStateIW3.cpp +++ b/src/ObjWriting/Game/IW3/Material/MaterialConstantZoneStateIW3.cpp @@ -6,7 +6,7 @@ #include "ObjWriting.h" #include "Zone/ZoneRegistry.h" -namespace IW3 +namespace { const char* KNOWN_CONSTANT_NAMES[]{ "worldViewProjectionMatrix", @@ -197,7 +197,10 @@ namespace IW3 "worldMap", "worldMapSampler", }; +} // namespace +namespace IW3 +{ void MaterialConstantZoneState::ExtractNamesFromZoneInternal() { for (const auto* zone : ZoneRegistry::GetRegistryForGame(GameId::IW3)->Zones()) @@ -219,7 +222,7 @@ namespace IW3 } } - unsigned MaterialConstantZoneState::HashString(const std::string& str) + unsigned MaterialConstantZoneState::HashString(const std::string& str) const { return Common::R_HashString(str.c_str()); } diff --git a/src/ObjWriting/Game/IW3/Material/MaterialConstantZoneStateIW3.h b/src/ObjWriting/Game/IW3/Material/MaterialConstantZoneStateIW3.h index f46d514b..a4926b03 100644 --- a/src/ObjWriting/Game/IW3/Material/MaterialConstantZoneStateIW3.h +++ b/src/ObjWriting/Game/IW3/Material/MaterialConstantZoneStateIW3.h @@ -13,6 +13,6 @@ namespace IW3 void ExtractNamesFromZoneInternal() override; void ExtractNamesFromTechnique(const MaterialTechnique* technique); void AddStaticKnownNames() override; - unsigned HashString(const std::string& str) override; + [[nodiscard]] unsigned HashString(const std::string& str) const override; }; } // namespace IW3 diff --git a/src/ObjWriting/Game/IW4/Material/MaterialConstantZoneStateIW4.cpp b/src/ObjWriting/Game/IW4/Material/MaterialConstantZoneStateIW4.cpp index 5524e905..0a77207e 100644 --- a/src/ObjWriting/Game/IW4/Material/MaterialConstantZoneStateIW4.cpp +++ b/src/ObjWriting/Game/IW4/Material/MaterialConstantZoneStateIW4.cpp @@ -6,7 +6,7 @@ #include "ObjWriting.h" #include "Zone/ZoneRegistry.h" -namespace IW4 +namespace { const char* KNOWN_CONSTANT_NAMES[]{ "worldViewProjectionMatrix", @@ -197,7 +197,10 @@ namespace IW4 "worldMap", "worldMapSampler", }; +} // namespace +namespace IW4 +{ void MaterialConstantZoneState::ExtractNamesFromZoneInternal() { for (const auto* zone : ZoneRegistry::GetRegistryForGame(GameId::IW4)->Zones()) @@ -230,7 +233,7 @@ namespace IW4 AddTextureDefName(knownTextureDefName); } - unsigned MaterialConstantZoneState::HashString(const std::string& str) + unsigned MaterialConstantZoneState::HashString(const std::string& str) const { return Common::R_HashString(str.c_str()); } diff --git a/src/ObjWriting/Game/IW4/Material/MaterialConstantZoneStateIW4.h b/src/ObjWriting/Game/IW4/Material/MaterialConstantZoneStateIW4.h index edde10f8..0ded901d 100644 --- a/src/ObjWriting/Game/IW4/Material/MaterialConstantZoneStateIW4.h +++ b/src/ObjWriting/Game/IW4/Material/MaterialConstantZoneStateIW4.h @@ -11,6 +11,6 @@ namespace IW4 protected: void ExtractNamesFromZoneInternal() override; void AddStaticKnownNames() override; - unsigned HashString(const std::string& str) override; + [[nodiscard]] unsigned HashString(const std::string& str) const override; }; } // namespace IW4 diff --git a/src/ObjWriting/Game/IW5/Material/MaterialConstantZoneStateIW5.cpp b/src/ObjWriting/Game/IW5/Material/MaterialConstantZoneStateIW5.cpp index 753470de..486ec6d5 100644 --- a/src/ObjWriting/Game/IW5/Material/MaterialConstantZoneStateIW5.cpp +++ b/src/ObjWriting/Game/IW5/Material/MaterialConstantZoneStateIW5.cpp @@ -6,7 +6,7 @@ #include "ObjWriting.h" #include "Zone/ZoneRegistry.h" -namespace IW5 +namespace { const char* KNOWN_CONSTANT_NAMES[]{ "worldViewProjectionMatrix", @@ -197,7 +197,10 @@ namespace IW5 "worldMap", "worldMapSampler", }; +} // namespace +namespace IW5 +{ void MaterialConstantZoneState::ExtractNamesFromZoneInternal() { for (const auto* zone : ZoneRegistry::GetRegistryForGame(GameId::IW5)->Zones()) @@ -230,7 +233,7 @@ namespace IW5 AddTextureDefName(knownTextureDefName); } - unsigned MaterialConstantZoneState::HashString(const std::string& str) + unsigned MaterialConstantZoneState::HashString(const std::string& str) const { return Common::R_HashString(str.c_str()); } diff --git a/src/ObjWriting/Game/IW5/Material/MaterialConstantZoneStateIW5.h b/src/ObjWriting/Game/IW5/Material/MaterialConstantZoneStateIW5.h index d8a33350..8bdc39d8 100644 --- a/src/ObjWriting/Game/IW5/Material/MaterialConstantZoneStateIW5.h +++ b/src/ObjWriting/Game/IW5/Material/MaterialConstantZoneStateIW5.h @@ -11,6 +11,6 @@ namespace IW5 protected: void ExtractNamesFromZoneInternal() override; void AddStaticKnownNames() override; - unsigned HashString(const std::string& str) override; + [[nodiscard]] unsigned HashString(const std::string& str) const override; }; } // namespace IW5 diff --git a/src/ObjWriting/Game/T5/Material/MaterialConstantZoneStateT5.cpp b/src/ObjWriting/Game/T5/Material/MaterialConstantZoneStateT5.cpp index 44804ceb..44f3f87c 100644 --- a/src/ObjWriting/Game/T5/Material/MaterialConstantZoneStateT5.cpp +++ b/src/ObjWriting/Game/T5/Material/MaterialConstantZoneStateT5.cpp @@ -6,7 +6,7 @@ #include "ObjWriting.h" #include "Zone/ZoneRegistry.h" -namespace T5 +namespace { const char* KNOWN_CONSTANT_NAMES[]{ "AngularVelocityScale", @@ -471,7 +471,10 @@ namespace T5 "ui3d", "ui3dSampler", }; +} // namespace +namespace T5 +{ void MaterialConstantZoneState::ExtractNamesFromZoneInternal() { for (const auto* zone : ZoneRegistry::GetRegistryForGame(GameId::T5)->Zones()) @@ -493,7 +496,7 @@ namespace T5 } } - unsigned MaterialConstantZoneState::HashString(const std::string& str) + unsigned MaterialConstantZoneState::HashString(const std::string& str) const { return Common::R_HashString(str.c_str()); } diff --git a/src/ObjWriting/Game/T5/Material/MaterialConstantZoneStateT5.h b/src/ObjWriting/Game/T5/Material/MaterialConstantZoneStateT5.h index f9c83922..f2a065b8 100644 --- a/src/ObjWriting/Game/T5/Material/MaterialConstantZoneStateT5.h +++ b/src/ObjWriting/Game/T5/Material/MaterialConstantZoneStateT5.h @@ -7,12 +7,12 @@ namespace T5 { - class MaterialConstantZoneState final : public AbstractMaterialConstantZoneStateDx11 + class MaterialConstantZoneState final : public AbstractMaterialConstantZoneStateDx9 { protected: void ExtractNamesFromZoneInternal() override; void ExtractNamesFromTechnique(const MaterialTechnique* technique); void AddStaticKnownNames() override; - unsigned HashString(const std::string& str) override; + [[nodiscard]] unsigned HashString(const std::string& str) const override; }; } // namespace T5 diff --git a/src/ObjWriting/Game/T6/Material/MaterialConstantZoneStateT6.cpp b/src/ObjWriting/Game/T6/Material/MaterialConstantZoneStateT6.cpp index 966a0ff4..9df3cc4d 100644 --- a/src/ObjWriting/Game/T6/Material/MaterialConstantZoneStateT6.cpp +++ b/src/ObjWriting/Game/T6/Material/MaterialConstantZoneStateT6.cpp @@ -6,7 +6,7 @@ #include "ObjWriting.h" #include "Zone/ZoneRegistry.h" -namespace T6 +namespace { const char* KNOWN_CONSTANT_NAMES[]{ "AngularVelocityScale", @@ -471,7 +471,10 @@ namespace T6 "ui3d", "ui3dSampler", }; +} // namespace +namespace T6 +{ void MaterialConstantZoneState::ExtractNamesFromZoneInternal() { for (const auto* zone : ZoneRegistry::GetRegistryForGame(GameId::T6)->Zones()) @@ -493,7 +496,7 @@ namespace T6 } } - unsigned MaterialConstantZoneState::HashString(const std::string& str) + unsigned MaterialConstantZoneState::HashString(const std::string& str) const { return Common::R_HashString(str.c_str()); } diff --git a/src/ObjWriting/Game/T6/Material/MaterialConstantZoneStateT6.h b/src/ObjWriting/Game/T6/Material/MaterialConstantZoneStateT6.h index 148169eb..674e808d 100644 --- a/src/ObjWriting/Game/T6/Material/MaterialConstantZoneStateT6.h +++ b/src/ObjWriting/Game/T6/Material/MaterialConstantZoneStateT6.h @@ -13,6 +13,6 @@ namespace T6 void ExtractNamesFromZoneInternal() override; void ExtractNamesFromTechnique(const MaterialTechnique* technique); void AddStaticKnownNames() override; - unsigned HashString(const std::string& str) override; + [[nodiscard]] unsigned HashString(const std::string& str) const override; }; } // namespace T6 diff --git a/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp b/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp index e2c6604e..af1d8f22 100644 --- a/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp +++ b/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp @@ -1,5 +1,6 @@ #include "TechsetDumperT6.h" +#include "Game/T6/Material/MaterialConstantZoneStateT6.h" #include "Game/T6/Techset/TechsetConstantsT6.h" #include "Shader/ShaderCommon.h" #include "Techset/CommonTechniqueDumper.h" @@ -77,6 +78,183 @@ namespace }; } + techset::CommonShaderArg ConvertToCommonArg(const MaterialShaderArgument& arg) + { + 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 = {.dx11 = + { + .m_location = arg.location.offset, + .m_size = arg.size, + .m_buffer = arg.buffer, + }}, + .m_value = { + .code_const_source = static_cast(arg.u.codeConst.index), + } + }; + + 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, + } + }; + + 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(arg.u.codeSampler), + } + }; + + 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, + } + }; + + default: + case MTL_ARG_LITERAL_VERTEX_CONST: + case MTL_ARG_LITERAL_PIXEL_CONST: + 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], + }, } + }; + } + + 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 = {}, + }; + } + } + + techset::CommonTechniqueShader ConvertToCommonShader(const MaterialPass& pass, const MaterialVertexShader* vertexShader) + { + techset::CommonTechniqueShader result{}; + if (!vertexShader) + return result; + + if (vertexShader->name) + result.m_name = vertexShader->name; + + 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; + } + } + } + + return result; + } + + techset::CommonTechniqueShader ConvertToCommonShader(const MaterialPass& pass, const MaterialPixelShader* pixelShader) + { + techset::CommonTechniqueShader result{}; + if (!pixelShader) + return result; + + if (pixelShader->name) + result.m_name = pixelShader->name; + + 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; + } + } + } + + return result; + } + techset::CommonTechnique ConvertToCommonTechnique(const MaterialTechnique& technique) { std::vector passes; @@ -85,38 +263,11 @@ namespace { const auto& pass = technique.passArray[passIndex]; - techset::CommonTechniqueShader vertexShader{}; - techset::CommonTechniqueShader pixelShader{}; - - if (pass.vertexShader) - { - if (pass.vertexShader->name) - vertexShader.m_name = pass.vertexShader->name; - - if (pass.vertexShader->prog.loadDef.program) - { - vertexShader.m_shader_bin = pass.vertexShader->prog.loadDef.program; - vertexShader.m_shader_bin_size = pass.vertexShader->prog.loadDef.programSize * sizeof(uint32_t); - } - } - - if (pass.pixelShader) - { - if (pass.pixelShader->name) - pixelShader.m_name = pass.pixelShader->name; - - if (pass.pixelShader->prog.loadDef.program) - { - pixelShader.m_shader_bin = pass.pixelShader->prog.loadDef.program; - pixelShader.m_shader_bin_size = pass.pixelShader->prog.loadDef.programSize * sizeof(uint32_t); - } - } - passes.emplace_back(techset::CommonPass{ .m_sampler_flags = pass.customSamplerFlags, .m_dx_version = techset::DxVersion::DX11, - .m_vertex_shader = vertexShader, - .m_pixel_shader = pixelShader, + .m_vertex_shader = ConvertToCommonShader(pass, pass.vertexShader), + .m_pixel_shader = ConvertToCommonShader(pass, pass.pixelShader), .m_vertex_declaration = ConvertToCommonVertexDeclaration(pass.vertexDecl), }); } @@ -130,17 +281,22 @@ namespace void DumpTechniques(AssetDumpingContext& context, const MaterialTechniqueSet& techset) { + static techset::CommonCodeSourceInfos codeSourceInfos(commonCodeConstSources, + std::extent_v, + commonCodeSamplerSources, + std::extent_v); static techset::CommonStreamRoutingInfos routingInfos( streamRoutingSources, std::extent_v, streamRoutingDestinations, std::extent_v); auto* techniqueState = context.GetZoneAssetDumperState(); + const auto* materialConstantState = context.GetZoneAssetDumperState(); for (const auto* technique : techset.techniques) { if (technique && techniqueState->ShouldDumpTechnique(technique)) { const auto commonTechnique = ConvertToCommonTechnique(*technique); - techset::DumpCommonTechnique(routingInfos, context, commonTechnique); + techset::DumpCommonTechnique(context, commonTechnique, codeSourceInfos, routingInfos, *materialConstantState); } } } @@ -178,6 +334,12 @@ namespace techset { } + void DumperT6::Dump(AssetDumpingContext& context) + { + context.GetZoneAssetDumperState()->EnsureInitialized(); + AbstractAssetDumper::Dump(context); + } + void DumperT6::DumpAsset(AssetDumpingContext& context, const XAssetInfo& asset) { const auto* techniqueSet = asset.Asset(); diff --git a/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.h b/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.h index c4093001..bcc14246 100644 --- a/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.h +++ b/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.h @@ -10,6 +10,8 @@ namespace techset public: explicit DumperT6(const AssetPool& pool); + void Dump(AssetDumpingContext& context) override; + protected: void DumpAsset(AssetDumpingContext& context, const XAssetInfo& asset) override; }; diff --git a/src/ObjWriting/Material/AbstractMaterialConstantZoneState.cpp b/src/ObjWriting/Material/AbstractMaterialConstantZoneState.cpp index c986878a..363b7bac 100644 --- a/src/ObjWriting/Material/AbstractMaterialConstantZoneState.cpp +++ b/src/ObjWriting/Material/AbstractMaterialConstantZoneState.cpp @@ -9,13 +9,22 @@ namespace { - constexpr const char* SAMPLER_STR = "Sampler"; - constexpr const char* GLOBALS_CBUFFER_NAME = "$Globals"; - constexpr const char* PER_OBJECT_CONSTS_CBUFFER_NAME = "PerObjectConsts"; + constexpr auto SAMPLER_STR = "Sampler"; + constexpr auto GLOBALS_CBUFFER_NAME = "$Globals"; + constexpr auto PER_PRIM_CONSTS_CBUFFER_NAME = "PerPrimConsts"; + constexpr auto PER_OBJECT_CONSTS_CBUFFER_NAME = "PerObjectConsts"; } // namespace -void AbstractMaterialConstantZoneState::ExtractNamesFromZone() +AbstractMaterialConstantZoneState::AbstractMaterialConstantZoneState() + : m_initialized(false) { +} + +void AbstractMaterialConstantZoneState::EnsureInitialized() +{ + if (m_initialized) + return; + con::debug("Building material constant name lookup..."); const auto begin = std::chrono::high_resolution_clock::now(); @@ -31,6 +40,8 @@ void AbstractMaterialConstantZoneState::ExtractNamesFromZone() durationInMs.count(), m_constant_names_from_shaders.size(), m_texture_def_names_from_shaders.size()); + + m_initialized = true; } bool AbstractMaterialConstantZoneState::GetConstantName(const unsigned hash, std::string& constantName) const @@ -124,6 +135,12 @@ void AbstractMaterialConstantZoneStateDx11::ExtractNamesFromShader(const void* s return constantBuffer.m_name == GLOBALS_CBUFFER_NAME; }); + const auto perPrimConsts = std::ranges::find_if(std::as_const(shaderInfo->m_constant_buffers), + [](const d3d11::ConstantBuffer& constantBuffer) + { + return constantBuffer.m_name == PER_PRIM_CONSTS_CBUFFER_NAME; + }); + const auto perObjectConsts = std::ranges::find_if(std::as_const(shaderInfo->m_constant_buffers), [](const d3d11::ConstantBuffer& constantBuffer) { @@ -136,6 +153,12 @@ void AbstractMaterialConstantZoneStateDx11::ExtractNamesFromShader(const void* s AddConstantName(variable.m_name); } + if (perPrimConsts != shaderInfo->m_constant_buffers.end()) + { + for (const auto& variable : perPrimConsts->m_variables) + AddConstantName(variable.m_name); + } + if (perObjectConsts != shaderInfo->m_constant_buffers.end()) { for (const auto& variable : perObjectConsts->m_variables) diff --git a/src/ObjWriting/Material/AbstractMaterialConstantZoneState.h b/src/ObjWriting/Material/AbstractMaterialConstantZoneState.h index 2a7734d8..6100a9cf 100644 --- a/src/ObjWriting/Material/AbstractMaterialConstantZoneState.h +++ b/src/ObjWriting/Material/AbstractMaterialConstantZoneState.h @@ -9,20 +9,24 @@ class AbstractMaterialConstantZoneState : public IZoneAssetDumperState { public: - void ExtractNamesFromZone(); + void EnsureInitialized(); bool GetConstantName(unsigned hash, std::string& constantName) const; bool GetTextureDefName(unsigned hash, std::string& textureDefName) const; + [[nodiscard]] virtual unsigned HashString(const std::string& str) const = 0; + protected: + AbstractMaterialConstantZoneState(); + virtual void ExtractNamesFromShader(const void* shader, size_t shaderSize) = 0; virtual void ExtractNamesFromZoneInternal() = 0; virtual void AddStaticKnownNames() = 0; - virtual unsigned HashString(const std::string& str) = 0; bool ShouldDumpFromStruct(const void* pStruct); void AddConstantName(const std::string& constantName); bool AddTextureDefName(const std::string& textureDefName); + bool m_initialized; std::unordered_set m_dumped_structs; std::unordered_map m_constant_names_from_shaders; std::unordered_map m_texture_def_names_from_shaders; diff --git a/src/ObjWriting/Material/MaterialJsonDumper.cpp.template b/src/ObjWriting/Material/MaterialJsonDumper.cpp.template index c62ddc9f..b566e1c6 100644 --- a/src/ObjWriting/Material/MaterialJsonDumper.cpp.template +++ b/src/ObjWriting/Material/MaterialJsonDumper.cpp.template @@ -369,7 +369,7 @@ namespace material void CLASS_NAME::Dump(AssetDumpingContext& context) { auto* materialConstantState = context.GetZoneAssetDumperState(); - materialConstantState->ExtractNamesFromZone(); + materialConstantState->EnsureInitialized(); AbstractAssetDumper::Dump(context); } diff --git a/src/ObjWriting/Techset/CommonTechniqueDumper.cpp b/src/ObjWriting/Techset/CommonTechniqueDumper.cpp index a76358a1..329f6d2c 100644 --- a/src/ObjWriting/Techset/CommonTechniqueDumper.cpp +++ b/src/ObjWriting/Techset/CommonTechniqueDumper.cpp @@ -4,6 +4,7 @@ #include "Shader/D3D11ShaderAnalyser.h" #include "Shader/D3D9ShaderAnalyser.h" #include "Techset/TechsetCommon.h" +#include "Utils/Logging/Log.h" #include #include @@ -21,9 +22,14 @@ namespace class TechniqueFileWriter : public AbstractTextDumper { public: - TechniqueFileWriter(const CommonStreamRoutingInfos& routingInfos, std::ostream& stream) + TechniqueFileWriter(std::ostream& stream, + const CommonCodeSourceInfos& codeSourceInfos, + const CommonStreamRoutingInfos& routingInfos, + const AbstractMaterialConstantZoneState& constantZoneState) : AbstractTextDumper(stream), - m_routing_infos(routingInfos) + m_code_source_infos(codeSourceInfos), + m_routing_infos(routingInfos), + m_constant_zone_state(constantZoneState) { } @@ -45,11 +51,11 @@ namespace #endif for (const auto& pass : technique.m_passes) - DumpPass(pass); + DumpPass(technique, pass); } private: - void DumpPass(const CommonPass& pass) + void DumpPass(const CommonTechnique& technique, const CommonPass& pass) { m_stream << "{\n"; IncIndent(); @@ -67,8 +73,8 @@ namespace #endif DumpStateMap(); - DumpShader(pass.m_vertex_shader, TechniqueShaderType::VERTEX_SHADER, pass.m_dx_version); - DumpShader(pass.m_pixel_shader, TechniqueShaderType::PIXEL_SHADER, pass.m_dx_version); + DumpShader(technique, pass.m_vertex_shader, TechniqueShaderType::VERTEX_SHADER, pass.m_dx_version); + DumpShader(technique, pass.m_pixel_shader, TechniqueShaderType::PIXEL_SHADER, pass.m_dx_version); DumpVertexDecl(pass.m_vertex_declaration); DecIndent(); @@ -83,12 +89,15 @@ namespace m_stream << "stateMap \"passthrough\"; // TODO\n"; } - void DumpShader(const CommonTechniqueShader& shader, const TechniqueShaderType shaderType, const DxVersion dxVersion) const + void DumpShader(const CommonTechnique& technique, const CommonTechniqueShader& shader, const TechniqueShaderType shaderType, const DxVersion dxVersion) { if (!shader.m_shader_bin) { if (!shader.m_name.empty()) - m_stream << std::format("// Cannot dump shader {} as its data is not loaded\n", shader.m_name); + { + m_stream << std::format("// ERROR: Cannot dump shader {} as its data is not loaded\n", shader.m_name); + con::error("Technique {}: Cannot dump shader {} as its data is not loaded\n", technique.m_name, shader.m_name); + } return; } @@ -103,6 +112,11 @@ namespace versionMajor = shaderInfo->m_version_major; versionMinor = shaderInfo->m_version_minor; + + DumpShaderHeader(shader, shaderType, versionMajor, versionMinor); + + for (const auto& arg : shader.m_args) + DumpShaderArgDx9(technique, arg, *shaderInfo); } else { @@ -114,8 +128,20 @@ namespace versionMajor = shaderInfo->m_version_major; versionMinor = shaderInfo->m_version_minor; + + DumpShaderHeader(shader, shaderType, versionMajor, versionMinor); + + for (const auto& arg : shader.m_args) + DumpShaderArgDx11(technique, arg, *shaderInfo); } + DecIndent(); + Indent(); + m_stream << "}\n"; + } + + void DumpShaderHeader(const CommonTechniqueShader& shader, const TechniqueShaderType shaderType, unsigned versionMajor, unsigned versionMinor) + { const auto shaderTypeName = shaderType == TechniqueShaderType::VERTEX_SHADER ? "vertexShader" : "pixelShader"; m_stream << "\n"; @@ -123,9 +149,225 @@ namespace m_stream << std::format("{} {}.{} \"{}\"\n", shaderTypeName, versionMajor, versionMinor, shader.m_name); Indent(); m_stream << "{\n"; + IncIndent(); + } - Indent(); - m_stream << "}\n"; + void DumpShaderArgDx9(const CommonTechnique& technique, const CommonShaderArg& arg, const d3d9::ShaderInfo& shaderInfo) const + { + const auto expectedRegisterSet = arg.m_type == CommonShaderArgType::CODE_SAMPLER || arg.m_type == CommonShaderArgType::MATERIAL_SAMPLER + ? d3d9::RegisterSet::SAMPLER + : d3d9::RegisterSet::FLOAT_4; + const auto destinationRegister = arg.m_destination.dx9.m_destination_register; + const auto targetShaderArg = std::ranges::find_if(shaderInfo.m_constants, + [destinationRegister, expectedRegisterSet](const d3d9::ShaderConstant& constant) + { + return constant.m_register_set == expectedRegisterSet + && constant.m_register_index <= destinationRegister + && constant.m_register_index + constant.m_register_count > destinationRegister; + }); + + assert(targetShaderArg != shaderInfo.m_constants.end()); + if (targetShaderArg == shaderInfo.m_constants.end()) + { + Indent(); + m_stream << std::format("// Unrecognized arg dest: {} type: {}\n", destinationRegister, static_cast(arg.m_type)); + con::error("Technique {}: Could not find arg (type: {}; dest: {}) in shader", + technique.m_name, + destinationRegister, + static_cast(arg.m_type)); + return; + } + + std::string codeDestAccessor; + if (targetShaderArg->m_type_elements > 1) + { + codeDestAccessor = std::format("{}[{}]", targetShaderArg->m_name, destinationRegister - targetShaderArg->m_register_index); + } + else + codeDestAccessor = targetShaderArg->m_name; + + DumpShaderArg(technique, arg, codeDestAccessor); + } + + void DumpShaderArgDx11(const CommonTechnique& technique, const CommonShaderArg& arg, const d3d11::ShaderInfo& shaderInfo) const + { + const auto& destination = arg.m_destination.dx11; + if (arg.m_type == CommonShaderArgType::CODE_CONST || arg.m_type == CommonShaderArgType::MATERIAL_CONST + || arg.m_type == CommonShaderArgType::LITERAL_CONST) + { + const auto boundResource = std::ranges::find_if(shaderInfo.m_bound_resources, + [destination](const d3d11::BoundResource& resource) + { + return resource.m_type == d3d11::BoundResourceType::CBUFFER + && resource.m_bind_point >= destination.m_buffer + && resource.m_bind_point + resource.m_bind_count > destination.m_buffer; + }); + if (boundResource == shaderInfo.m_bound_resources.end()) + { + Indent(); + m_stream << std::format("// Could not find bound resource for arg buffer: {} offset: {} type: {}\n", + destination.m_buffer, + destination.m_location, + static_cast(arg.m_type)); + con::error("Technique {}: Could not find bound resource for arg (buffer: {} offset: {} type: {}) in shader", + technique.m_name, + destination.m_buffer, + destination.m_location, + static_cast(arg.m_type)); + return; + } + const auto buffer = std::ranges::find_if(shaderInfo.m_constant_buffers, + [&boundResource](const d3d11::ConstantBuffer& constantBuffer) + { + return constantBuffer.m_name == boundResource->m_name; + }); + if (buffer == shaderInfo.m_constant_buffers.end()) + { + Indent(); + m_stream << std::format("// Could not find buffer for bound resource: {}\n", boundResource->m_name); + con::error("Technique {}: Could not find buffer for bound resource: {} in shader", technique.m_name, boundResource->m_name); + return; + } + + const auto variable = std::ranges::find_if(buffer->m_variables, + [destination](const d3d11::ConstantBufferVariable& var) + { + return var.m_offset <= destination.m_location + && var.m_offset + var.m_size >= destination.m_location + destination.m_size; + }); + if (variable == buffer->m_variables.end()) + { + Indent(); + m_stream << std::format("// Could not find variable in buffer: {} offset: {} type: {}\n", + buffer->m_name, + destination.m_location, + static_cast(arg.m_type)); + con::error("Technique {}: Could not find variable in buffer for arg (buffer: {} offset: {} type: {}) in shader", + technique.m_name, + buffer->m_name, + destination.m_location, + static_cast(arg.m_type)); + return; + } + + DumpShaderArg(technique, arg, variable->m_name); + } + else + { + assert(arg.m_type == CommonShaderArgType::CODE_SAMPLER || arg.m_type == CommonShaderArgType::MATERIAL_SAMPLER); + + const auto boundResource = std::ranges::find_if(shaderInfo.m_bound_resources, + [destination](const d3d11::BoundResource& resource) + { + return (resource.m_type == d3d11::BoundResourceType::SAMPLER + || resource.m_type == d3d11::BoundResourceType::TEXTURE) + && resource.m_bind_point == destination.m_location; + }); + if (boundResource == shaderInfo.m_bound_resources.end()) + { + Indent(); + m_stream << std::format("// Could not find buffer for arg buffer: {} offset: {} type: {}\n", + destination.m_buffer, + destination.m_location, + static_cast(arg.m_type)); + con::error("Technique {}: Could not find buffer for arg (buffer: {} offset: {} type: {}) in shader", + technique.m_name, + destination.m_buffer, + destination.m_location, + static_cast(arg.m_type)); + return; + } + DumpShaderArg(technique, arg, boundResource->m_name); + } + } + + void DumpShaderArg(const CommonTechnique& technique, const CommonShaderArg& arg, std::string codeDestAccessor) const + { + if (arg.m_type == CommonShaderArgType::CODE_CONST) + { + const auto constSourceInfo = m_code_source_infos.GetInfoForCodeConstSource(arg.m_value.code_const_source); + if (constSourceInfo) + { + if (codeDestAccessor != constSourceInfo->accessor) + { + Indent(); + m_stream << std::format("{} = constant.{};\n", codeDestAccessor, constSourceInfo->accessor); + } + else + { +#ifdef TECHSET_DEBUG + Indent(); + m_stream << std::format("// Omitted due to matching accessors: {} = constant.{};\n", codeDestAccessor, constSourceInfo->accessor); +#endif + } + } + else + { + assert(false); + Indent(); + m_stream << std::format("// ERROR: Could not find code source info for const: {}\n", codeDestAccessor); + con::error("Technique {}: Could not find code source info for const {}", technique.m_name, codeDestAccessor); + } + } + else if (arg.m_type == CommonShaderArgType::CODE_SAMPLER) + { + const auto samplerSourceInfo = m_code_source_infos.GetInfoForCodeSamplerSource(arg.m_value.code_sampler_source); + if (samplerSourceInfo) + { + if (codeDestAccessor != samplerSourceInfo->accessor) + { + Indent(); + m_stream << std::format("{} = sampler.{};\n", codeDestAccessor, samplerSourceInfo->accessor); + } + else + { +#ifdef TECHSET_DEBUG + Indent(); + m_stream << std::format("// Omitted due to matching accessors: {} = sampler.{};\n", codeDestAccessor, samplerSourceInfo->accessor); +#endif + } + } + else + { + assert(false); + Indent(); + m_stream << std::format("// ERROR: Could not find code source info for sampler: {}\n", codeDestAccessor); + con::error("Technique {}: Could not find code source info for sampler {}", technique.m_name, codeDestAccessor); + } + } + else if (arg.m_type == CommonShaderArgType::LITERAL_CONST) + { + Indent(); + m_stream << std::format("{} = float4({}, {}, {}, {});\n", + codeDestAccessor, + arg.m_value.literal_value[0], + arg.m_value.literal_value[1], + arg.m_value.literal_value[2], + arg.m_value.literal_value[3]); + } + else if (arg.m_type == CommonShaderArgType::MATERIAL_CONST || arg.m_type == CommonShaderArgType::MATERIAL_SAMPLER) + { + Indent(); + + std::string materialPropertyName; + if (m_constant_zone_state.GetConstantName(arg.m_value.name_hash, materialPropertyName) + || m_constant_zone_state.GetTextureDefName(arg.m_value.name_hash, materialPropertyName)) + { + m_stream << std::format("{} = material.{};\n", codeDestAccessor, materialPropertyName); + } + else if (m_constant_zone_state.HashString(codeDestAccessor) == arg.m_value.name_hash) + { + m_stream << std::format("{} = material.{};\n", codeDestAccessor, codeDestAccessor); + } + else + { + m_stream << std::format("{} = material.#0x{:x};\n", codeDestAccessor, arg.m_value.name_hash); + } + } + else + { + assert(false); + } } void DumpVertexDecl(const CommonVertexDeclaration& vertexDeclaration) const @@ -143,18 +385,24 @@ namespace } } + const CommonCodeSourceInfos& m_code_source_infos; const CommonStreamRoutingInfos& m_routing_infos; + const AbstractMaterialConstantZoneState& m_constant_zone_state; }; } // namespace namespace techset { - void DumpCommonTechnique(const CommonStreamRoutingInfos& routingInfos, const AssetDumpingContext& context, const CommonTechnique& technique) + void DumpCommonTechnique(const AssetDumpingContext& context, + const CommonTechnique& technique, + const CommonCodeSourceInfos& codeSourceInfos, + const CommonStreamRoutingInfos& routingInfos, + const AbstractMaterialConstantZoneState& constantZoneState) { const auto techniqueFile = context.OpenAssetFile(GetFileNameForTechniqueName(technique.m_name)); if (techniqueFile) { - TechniqueFileWriter writer(routingInfos, *techniqueFile); + TechniqueFileWriter writer(*techniqueFile, codeSourceInfos, routingInfos, constantZoneState); writer.DumpTechnique(technique); } } diff --git a/src/ObjWriting/Techset/CommonTechniqueDumper.h b/src/ObjWriting/Techset/CommonTechniqueDumper.h index 3794d71d..4a3dc943 100644 --- a/src/ObjWriting/Techset/CommonTechniqueDumper.h +++ b/src/ObjWriting/Techset/CommonTechniqueDumper.h @@ -1,9 +1,14 @@ #pragma once #include "Dumping/AssetDumpingContext.h" +#include "Material/AbstractMaterialConstantZoneState.h" #include "Techset/CommonTechnique.h" namespace techset { - void DumpCommonTechnique(const CommonStreamRoutingInfos& routingInfos, const AssetDumpingContext& context, const CommonTechnique& technique); + void DumpCommonTechnique(const AssetDumpingContext& context, + const CommonTechnique& technique, + const CommonCodeSourceInfos& codeSourceInfos, + const CommonStreamRoutingInfos& routingInfos, + const AbstractMaterialConstantZoneState& constantZoneState); } // namespace techset